News
Seven days of Black Friday madness — great deal from Serverspace!
Serverspace Black Friday
DC
August 26, 2022
Updated June 7, 2023

How to automate server deployment via CLI?

VPS

CLI

s2ctl is a Serverspace in the command line. The CLI gives you the ability to control your infrastructure via terminal, just like via the control panel. The tool is available on our Github.

Installation

s2ctl is available for Linux and Windows as a separate binary file. Download the archive from Github and unzip it.

Installation on Linux

  1. Download the archive from the GitHub repository:
    wget https://github.com/itglobalcom/s2ctl/releases/download/vX.X.X/s2ctl-vX.X.X-linux.tar.gz

    X.X.X.X is the number of the latest version of the utility.

  2. Unzip the downloaded archive:
    tar -xzf s2ctl-vX.X.X-linux.tar.gz
  3. Navigate to the created directory and run the s2ctl utility:
    cd s2ctl-vX.X.X-linux
    ./s2ctl --help
  4. (Optional) You can also add the directory which contains the s2ctl executable to the $PATH environment variable to access the utility from anywhere in the operating system. To see what is in the $PATH variable right now, type the command:
    echo $PATH

    To add a new directory to the list, use the command:

    export PATH=$PATH:""

    The $PATH variable is set by the shell each time it starts, but you can make it include the path to the utility in every new shell you open. The exact method depends on which shell you're using.
    For example, for bash you need to add the following line about the corresponding file:

    echo 'export PATH=$PATH:""' >> .bashrc

    Use the command to apply the changes:

    source ~/.bashrc

Installation on Windows

    1. Download the file s2ctl-vX.X.X-windows.zip from Github and unzip it.
    2. Run the command line:
      1. Press Win+R or Start → Search → Enter run → OK
      2. Enter cmd command → OK
    3. By default, the command line displays the home directory of the current user. Navigate to the directory with the extracted file:
      cd
    4. Go to the desired directory and run the command:
s2ctl --help
  1. (Optional) You can also add the directory where you placed the s2ctl binary to the PATH environment variable to access the utility from anywhere in the operating system.
    1. Find System (Control Panel) in Search, and open it.
    2. Click the Advanced system settings.
    3. Click on Environment Variables. In the System Variables section find the PATH variable and select it. Click Edit. If the PATH variable does not exist, click New.
    4. In the Edit System Variable (or New System Variable) window, specify the value for the PATH environment variable. Click OK. Close all remaining windows by clicking OK.

Authorization

In order to work with the CLI you must create an API key for the project and also a context. Otherwise, you will need to pass the API key with each request.

Context Creation

Using contexts simplifies the use of the s2ctl utility. In this case you do not have to explicitly specify the API key for each command.
To create a context, use the following command:

s2ctl context create -k -n

For example:

s2ctl context create -k lmGwbvllpIqIrKROOCLgE5Z941MKP5EYfbkgwtqJZGigfXUTpuYRpNQkCqShmm6r -n example

Key Transfer

To pass the API key explicitly, it must be specified at the end of the command with the --apikey option:

s2ctl --apikey

For example:

s2ctl images --apikey lmGwbvllpIqIrKROOCLgE5Z941MKP5EYfbkgwtqJZGigfXUTpuYRpNQkCqShmm6r

Usage Examples

Get information about the project with the following command:

s2ctl project show

This will return information about the project:

id: '1'
balance: '400.24'
currency: EUR
state: Active
created: '2019-04-08T10:35:53.7021047Z'

Create server:

s2ctl server create --name test-cli --location nj3 --image Ubuntu-20.04-X64 --cpu 2 --ram 2048M --volume boot:30720M --volume volume:10240M --public-network 50 --public-network 60

This will return the task ID, which can be used to track the server creation process:

task_id: lt1512053

Vote:
4 out of 5
Аverage rating : 4.5
Rated by: 10
1101 CT Amsterdam The Netherlands, Herikerbergweg 292
+31 20 262-58-98
700 300
ITGLOBAL.COM NL
700 300
We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.