Skip to end of metadata
Go to start of metadata

You can monitor Sauce Connect more easily with a Service Managment tool like systemd or upstart. These tools make using Sauce Connect a more fluid experience, and allow time for Sauce Connect to clean up upon exiting. This is useful in situations where you want to kill the Sauce Connect process, and start one instantly after that, because it takes time to shut down Sauce Connect remotely. By using these tools, you have a graceful way to shut down and restart your Sauce Connect instances that already account for the time involved for the shut down and clean up processes. 

Setting Up Systemd

  1. Navigate to your /local/bin directory where you want to install Sauce Connect.

    cd /usr/local/bin
  2. Download Sauce Connect. 

    wget https://saucelabs.com/downloads/sc-4.3.11-linux.tar.gz
  3. Untar the Sauce Connect file. 

    tar -zxvf sc-4.3.11-linux.tar.gz
  4. Copy the Sauce Connect file into a dedicated directory.

    cp sc-4.3.11-linux/bin/sc
  5. Make sure Sauce Connect is located in the correct directory.

    ls /usr/local/bin/sc
  6. Change to the system directory.

    cd /etc/systemd/system
  7. In the system directory, create a service file named 'sc.server' and copy the following text into it.  You will need to replace <USERNAME> and <ACCESSKEY> with your Sauce Labs username and access key.

    sc.server example file
    [Unit]
    Description=Sauce Connect
    After=network.target
    
    [Service]
    Type=simple
    User=nobody
    Group=nogroup
    ExecStart=/usr/local/bin/sc -u <USERNAME> -k <ACCESSKEY> -l /tmp/sc_long.log --pidfile /tmp/sc_long.pid --se-port 0
    
    [Install]
    WantedBy=multi-user.target

    (info) To have Sauce Connect restart automatically, add "Restart=always" in the '[Service]'s section of 'sc.server'.

  8. Reload the service file.

    sudo systemctl daemon-reload
  9. Start the service.

    sudo systemctl start sc.service
  10. Check the status of the service.

    sudo systemctl status sc.service
  11. You can stop the service with this command.

    sudo systemctl stop sc.service

Setting Up Upstart

  1. Navigate to your /local/bin directory where you want to install Sauce Connect.

    cd /usr/local/bin
  2. Download Sauce Connect. 

    wget https://saucelabs.com/downloads/sc-4.3.11-linux.tar.gz
  3. Untar the Sauce Connect file. 

    tar -zxvf sc-4.3.11-linux.tar.gz
  4. Copy the Sauce Connect file into a dedicated directory.

    cp sc-4.3.11-linux/bin/sc
  5. Make sure Sauce Connect is located in the correct directory.

    ls /usr/local/bin/sc
  6. Change to the /etc/init directory.

    cd /etc/init
  7. In the /etc/init directory, create a file sc.conf with these contents.
    Change the username and access key in the file to match your own.  

    sc.conf example file
    #
    #This Upstart config expects that Sauce Connect is installed at
    #/usr/local/bin/sc. Edit that path if it is installed somewhere else.
    #
    #Copy this file to /etc/init/sc.conf, and do:
    #
    # $ sudo initctl reload-configuration
    #
    #Then you can manage SC via the usual upstart tools, e.g.:
    #
    #$ sudo start sc
    #$ sudo restart sc
    #$ sudo stop sc
    #$ sudo status sc
    #
    start on filesystem and started networking
    stop on runlevel 06
    
    respawn
    respawn limit 15 5
    
    #Wait for tunnel shutdown when stopping Sauce Connect.
    kill timeout 120
    
    #Bump maximum number of open files/sockets.
    limit nofile 8192 8192
    
    #Make Sauce Connect output go to /var/log/upstart/sc.log.
    console log
    
    env LOGFILE="/tmp/sc_long.log"
    env PIDFILE="/tmp/sc_long.pid"
    env EXTRA_ARGS="--se-port 0"
    env SAUCE_USERNAME="CHANGEME" # XXX
    env SAUCE_ACCESS_KEY="CHANGEME" # XXX
    
    post-start script
      # Save the pidfile, since Sauce Connect might remove it before the
      # post-stop script gets a chance to run.
      n=0
      max_tries=30
      while [ $n -le $max_tries ]; do
        if [ -f $PIDFILE ]; then
          cp $PIDFILE ${PIDFILE}.saved
          break
        fi
        n=$((n+1))
        [ $n -ge $max_tries ] && exit 1
        sleep 1
      done
    end script
    
    post-stop script
      # Wait for Sauce Connect to shut down its tunnel.
      n=0
      max_tries=30
      pid="$(cat ${PIDFILE}.saved)"
      while [ $n -le $max_tries ]; do
        kill -0 $pid || break
        n=$((n+1))
        [ $n -ge $max_tries ] && exit 1
        sleep 1
      done
    end script
    
    setuid nobody
    setgid nogroup
    
    chdir /tmp
    
    exec /usr/local/bin/sc -l $LOGFILE --pidfile $PIDFILE $EXTRA_ARGS
  8. Reload the service.

    sudo initctl reload-configuration
  9. Start the service.

    sudo start sc
  10. Check the status of the service.

    sudo status sc
  11. You can stop the service with this command.

    sudo stop sc