We have some really exciting news to share with you. We have released our new super-geeky, extra-nerdy, arguably sexy sgcli utility. Why? Because we are all about productivity and know that sometimes you just need to do a quickie on your server. Of course we can do all of this from the control panel, but having to open a browser, navigate to the website, then going into the server and pressing the required button can be a hassle for something small. This is especially true for us Unix geeks, hell, that’s exactly why we love command line.
We are happy to announce that we just released the first version of our sgcli utility, a small program that allows you to perform many of the tasks you do in your control panel through the command line. You can perform quick operations like reboot a server or restart Apache without having to open the browser and login.
But enough foreplay, let’s install it! Download the sgcli.phar file and give it executable permissions or execute it with php sgcli.phar. You can place this file in your PATH so it is easy to execute.
To launch the shell, run:
$ sgcli.phar shell
If you run it without any configuration, it will ask you for your Control Panel credentials or it will let you connect with the our demo VPS account to play with it.
If you want to avoid to enter the credentials every time you execute the command you can add your API key and secret as environment variables:
$ export SG_API_KEY=yourkey
$ export SG_API_SECRET=yoursecret
In *nix you can add these to your ~/.profile file so they will be remembered every time you open the terminal. You can also add the environment variables in Windows.
If you have never setup the API key and secret, you will first need to enable it in the the profile section of the Control Panel.
Once you are logged in, you will get the list of servers under your account. If you only have one server, it will get selected automatically, so you can run commands like:
$ restart apache
You can also select a server from the list, by specifying the server name, part of the name or a numeric id from the server list.
$ server example.com
$ server myserver
$ server 3
Consult the sgcli documentation or the help command for more details.
The utility also provides a client utility to execute API calls from the command line, allowing you to create scripts that interact with your server. An example to reboot a server would be:
$ sgcli.phar client server/restart serverId=yourserverId
You can consult the API documentation to see the list of available commands.
You can also have sgcli functionality in your Symfony2 application. You can use the SGControlBundle to perform the same tasks our control panel does directly from your app, like creating domains, emails, dns records, managing apps and a lot more.