Scripting the Zeus/Stingray API

0 Flares Twitter 0 Facebook 0 Filament.io 0 Flares ×

So you are digging the Joyent API, you have your provisioning working with your Chef or Puppet Scripts.
Here is a shell script you can use to add that new box to your Stingray load balancer.
#!/bin/bash
zxtm=localhost
/opt/zeus/zxtm/bin/zcli << EOF
Pool.addPool ["JoyentDemo"],[["help.joyent.com:80","joyent.com:80","wiki.joyent.com:80"]]
Pool.setLoadBalancingAlgorithm ["JoyentDemo"], roundrobin
Pool.setPassiveMonitoring ["JoyentDemo"], 0
Pool.setMonitors ["JoyentDemo"], "Full HTTP"
Pool.setKeepalive ["JoyentDemo"], 1
VirtualServer.addVirtualServer ["JoyentDemo"],{"default_pool" : "JoyentDemo","port" : "80","protocol":"http"}
VirtualServer.setCompressionEnabled ["JoyentDemo"], yes
VirtualServer.setEnabled ["JoyentDemo"], 1
exit
EOF

How the Script Works
You can see how this script works when you break it down.
The first line specifies you are running this local to the Zeus/Stingray. if you want to run remotely, change the value of this line to ssh.
zxtm=localhost
The next line initializes two Stingray load balancing objects: Pool and VirtualServer. The rest of the script sets properties in these objects.
Tip: if you are running this locally, you do not need to specify a password since you are already on the appliance.
The zcli command invokes the Stingray Command Line interface. This line starts unix shell scripting to redirect standard output to the zcli using << EOF.
/opt/zeus/zxtm/bin/zcli << EOF
Tip: For more detailed information on the zcli, type "help" and press ENTER.
The next few lines set properties in the Pool object.
This line creates a pool called "myPool" and populates it with three different servers: help.joyent.com:80, joyent.com:80, and wiki.joyent.com:80.
Note: Remember to include the port number after the DNS or IP address.
Pool.addPool ["myPool"],[["help.joyent.com:80","joyent.com:80","wiki.joyent.com:80"]]
This line sets the type of load balancing to use with this pool. In the below line, the keyword "roundrobin" specifies the algorithm used.
Pool.setLoadBalancingAlgorithm ["myPool"], roundrobin
Below is a list of other supported algorithms. The keyword to use for each algorithm appears in bold.
roundrobin: Round Robin
wroundrobin: Weighted Round Robin
cells: Perceptive
connections: Least Connections
wconnections: Weighted Least Connections
responsetimes: Fastest Response Time
random: Random Node
This line enables or disables passive monitoring for the generated pool. Supported values are 0 and 1.
Note: To avoid seeing false positives on service checks, set this to a value of 0.
Pool.setPassiveMonitoring ["myPool"], 0
This line sets the monitoring type for the generated pool. Joyent usually recommends Full HTTP or Simple HTTP
Pool.setMonitors ["myPool"], "Full HTTP"
This line enables or disables keep-alive in the generated pool. Supported values are 0 and 1.
Pool.setKeepalive ["myPool"], 1
The next few lines set properties in the VirtualServer object.
This line creates a new virtual server called "myServer" that uses the pool created in the previous lines.
Note: Ensure that you also specify the port number and protocol. In this case, the port number is 80 and the protocol is HTTP.
VirtualServer.addVirtualServer ["myServer"],{"default_pool" : "myPool","port" : "80","protocol":"http"}
This line enables compression on the appliance. Joyent recommends using compression on the appliance, rather than the web server.
VirtualServer.setCompressionEnabled ["myServer"], yes
This line enables your new config.
VirtualServer.setEnabled ["myServer"], 1
The last couple lines exit from the zcli and close the script.
exit
EOF
That's it.
If you have any other questions or idea's for Zeus/Stingray articles, please use the comments field

Posted in Foundations, Technology | 1 Comment

One Response to Scripting the Zeus/Stingray API

Leave a Reply

0 Flares Twitter 0 Facebook 0 Filament.io 0 Flares ×