How to start Jetbrains License Server automatically on the Ubuntu system

startup-scriptsubuntu-14.04

Assuming I have my license server installed here: /opt/jetbrains-license-server, how do I configure it to start automatically?

Best Answer

The anwer of @chris-betti is correct. However for DEBIAN based systems I have three additions:

  1. ensure that runlevel 2 the license-server is also started
  2. ensure that there is a jetbrains user
  3. ensure that the PID file is in the correct location (/opt//logs/license-server.pid)

ad 1: see the script file below. You need to change the line # Default Start to read:

# Default-Start:     2 3 4 5

ad 2: Ensure that you have a 'jetbrains' system user that can start the service (and has permission to write in the directory where you installed the licenseserver

# as root
adduser --system --no-create-home jetbrains
chown jetbrains:nogroup -R /opt/jetbrains-license-server

ad 3: Regarding the PID file, you need to change the line with # pidfile: to:

# pidfile: /opt/jetbrains-license-server/logs/license-server.pid

Install the daemon:

There is one more addition to install the service into the various runlevels for debian based systems (Debian, Ubuntu). This will ensure that the service starts at boot and halts on halt.

# as root
update-rc.d jetbrains-license-server defaults
update-rc.d jetbrains-license-server enable

The script with all the changes

Here is the script with all the changes incorporated.

#
# chkconfig: 345 86 14
# description: Jetbrains License Server
# processname: license-server.sh
# pidfile: /opt/jetbrains-license-server/logs/license-server.pid

### BEGIN INIT INFO
# Provides:          jetbrains-license-server
# Required-Start:    $remote_fs $syslog $network
# Required-Stop:     $remote_fs $syslog $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start Jetbrains License Server
# Description:       Manages the Jetbrains License Server Service
### END INIT INFO

APP=jetbrains-license-server
USER=jetbrains
BASE=/opt/jetbrains-license-server

case "$1" in
  # Start command
  start)
    echo "Starting $APP"
    /bin/su -m $USER -c "cd $BASE && $BASE/bin/license-server.sh start &> /dev/null"
    ;;
  # Stop command
  stop)
    echo "Stopping $APP"
    /bin/su -m $USER -c "cd $BASE && $BASE/bin/license-server.sh stop &> /dev/null"
    echo "$APP stopped successfully"
    ;;
  # Restart command
  restart)
    echo "Restarting $APP"
    /bin/su -m $USER -c "cd $BASE && $BASE/bin/license-server.sh restart"
    ;;
  # Status command
  status)
    echo "$APP Status"
    /bin/su -m $USER -c "cd $BASE && $BASE/bin/license-server.sh status"
    ;;
  *)
    echo "Usage: /etc/init.d/$APP {start|restart|stop}"
    exit 1
    ;;
esac

exit 0