86 lines
1.9 KiB
Bash
86 lines
1.9 KiB
Bash
#!/bin/sh
|
|
|
|
# Author: Oscar Alvarez, 01/07/2016
|
|
NAME="strytond"
|
|
DESC="Tryton"
|
|
PSKUSER=psk
|
|
HOMEX=/home/${PSKUSER}
|
|
NAME_ENV=tryton60
|
|
VERSION="6.0"
|
|
DAEMON="${HOMEX}/.virtualenvs/${NAME_ENV}/bin/trytond"
|
|
|
|
PIDFILE="/var/run/$NAME.pid"
|
|
|
|
CONFIG="${HOMEX}/.trytond/trytond.conf"
|
|
OPTIONS="-c $CONFIG"
|
|
|
|
set -e
|
|
|
|
# Using the lsb functions to perform the operations.
|
|
. /lib/lsb/init-functions
|
|
|
|
# Exit if Tryton not installed
|
|
if [ ! -x "$DAEMON" ]; then
|
|
log_action_msg "$DESC: Could not find tryton executable. Exiting."
|
|
exit 2
|
|
fi
|
|
|
|
# Function to verify if trytond is already running
|
|
run_check() {
|
|
if [ -e /var/run/strytond.pid ]; then
|
|
status_of_proc -p /var/run/strytond.pid $DAEMON $NAME > /dev/null && RETVAL=0 || RETVAL="$?"
|
|
else
|
|
RETVAL="2"
|
|
fi
|
|
}
|
|
|
|
|
|
|
|
start_tryton() {
|
|
run_check
|
|
if [ $RETVAL = 0 ]; then
|
|
log_action_msg "$DESC: Already running with PID $(cat $PIDFILE). Aborting."
|
|
exit 2
|
|
else
|
|
log_daemon_msg "$DESC: Starting the server version ${VERSION}."
|
|
start-stop-daemon --start --pidfile /var/run/strytond.pid --make-pidfile --exec $DAEMON -v -- $OPTIONS
|
|
RETVAL=$?
|
|
log_end_msg
|
|
fi
|
|
}
|
|
|
|
|
|
stop_tryton() {
|
|
start-stop-daemon --stop --pidfile /var/run/strytond.pid
|
|
}
|
|
|
|
|
|
status_tryton() {
|
|
run_check
|
|
if [ $RETVAL = 0 ]; then
|
|
log_action_msg "$DESC: Currently running with PID $(cat /var/run/strytond.pid)."
|
|
else
|
|
log_action_msg "$DESC: Not currently running."
|
|
fi
|
|
exit $RETVAL
|
|
}
|
|
|
|
case "$1" in
|
|
start)
|
|
start_tryton
|
|
;;
|
|
stop)
|
|
stop_tryton
|
|
;;
|
|
restart)
|
|
stop_tryton && sleep 2 && start_tryton
|
|
;;
|
|
status)
|
|
status_tryton
|
|
;;
|
|
*)
|
|
echo "Usage: $0 {start|stop|restart|status}"
|
|
esac
|
|
|
|
exit 0
|