Assuming I have my license server installed here: /opt/jetbrains-license-server, how do I configure it to start automatically?
3 Answers
jochem's answer is more thorough and correct, please reference it.
First, create a jetbrains user on your server.
Second, assuming you choose to use init.d (System V), do the following:
$ touch /etc/init.d/jetbrains-license-server
$ chmod +x /etc/init.d/jetbrains-license-server
Now place the following contents in this file:
#!/bin/bash
# Startup script for Jetbrains License Server
#
# chkconfig: 345 86 14
# description: Jetbrains License Server
# processname: license-server.sh
# pidfile: /opt/jetbrains-license-server/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

- 380
- 3
- 14
The anwer of @chris-betti is correct. However for DEBIAN based systems I have three additions:
- ensure that runlevel 2 the license-server is also started
- ensure that there is a jetbrains user
- 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

- 38
- 4
-
This is a more thorough and correct answer than mine. I'm deleting my answer in favor of this, so please edit your answer to make it stand alone (i.e. don't reference corrections to mine). – Chris Betti Jan 21 '16 at 19:16
-
See my addendum to the answer below – oldNoakes Jul 29 '16 at 03:02
Both answers are correct though they fail in one respect,
If you are using the script for an Infrastructure as Code framework (e.g. Ansible/Puppet) which uses the status return code to determine what action to take, the script as provided, which always returns 0, will not successfully start up the application automatically when the app is stopped.
My addition to the script is to capture the return code for each of the delegated calls and use this as the exit code and the bottom:
#
# 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
RETCODE=0
case "$1" in
# Start command
start)
echo "Starting $APP"
/bin/su -m $USER -c "cd $BASE && $BASE/bin/license-server.sh start &> /dev/null"
RETCODE=$?
;;
# Stop command
stop)
echo "Stopping $APP"
/bin/su -m $USER -c "cd $BASE && $BASE/bin/license-server.sh stop &> /dev/null"
RETCODE=$?
;;
# Restart command
restart)
echo "Restarting $APP"
/bin/su -m $USER -c "cd $BASE && $BASE/bin/license-server.sh restart"
RETCODE=$?
;;
# Status command
status)
echo "$APP Status"
/bin/su -m $USER -c "cd $BASE && $BASE/bin/license-server.sh status"
RETCODE=$?
;;
*)
echo "Usage: /etc/init.d/$APP {start|restart|stop}"
exit 1
;;
esac
exit $RETCODE
You could expand this to provide useful messages to the user based on the return code but I have not bothered to go that far.

- 183
- 6