-
-
Save ashleyconnor/6a3a6f1c203eb1904624 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# init.d script for basexserver http://basex.org/ | |
# (c) 2012 Andy Bunce <[email protected]>, BSD | |
# (c) 2015 Ashley Connor <[email protected]>, LICENSE AS ABOVE | |
### BEGIN INIT INFO | |
# Provides: basex-server | |
# Required-Start: $syslog | |
# Required-Stop: $syslog | |
# Should-Start: $local_fs | |
# Should-Stop: $local_fs | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: basex-server - xml db | |
# Description: basex-server - xml db | |
### END INIT INFO | |
# Using the lsb functions to perform the operations. | |
. /lib/lsb/init-functions | |
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
DAEMON=/usr/bin/basexserver | |
NAME=basex-server | |
DESC=basex-server | |
PIDFILE=/var/run/basexserver.pid | |
test -x $DAEMON || exit 0 | |
test -x $DAEMONBOOTSTRAP || exit 0 | |
set -e | |
case "$1" in | |
start) | |
# Checked the PID file exists and check the actual status of process | |
if [ -e $PIDFILE ]; then | |
status_of_proc -p $PIDFILE $DAEMON "$NAME process" && status="0" || status="$?" | |
# If the status is SUCCESS then don't need to start again. | |
if [ $status = "0" ]; then | |
exit # Exit | |
fi | |
fi | |
log_daemon_msg "Starting the process" "$NAME" | |
if start-stop-daemon --start --umask 007 \ | |
--pidfile $PIDFILE --make-pidfile \ | |
--chuid basex:basex --chdir /home/basex \ | |
--exec $DAEMON -- "-S" | |
then | |
log_daemon_msg "$NAME process is not running" | |
log_end_msg 0 | |
else | |
log_daemon_msg "Failed to start $NAME" | |
log_end_msg 1 | |
fi | |
;; | |
stop) | |
if [ -e $PIDFILE ]; then | |
status_of_proc -p $PIDFILE $DAEMON "Stoppping the $NAME process" && status="0" || status="$?" | |
if [ "$status" = 0 ]; then | |
echo -n "Stopping $DESC: " | |
start-stop-daemon --start --retry 10 --oknodo \ | |
--chuid basex:basex --chdir /home/basex \ | |
--exec $DAEMON -- stop | |
/bin/rm -rf $PIDFILE | |
fi | |
else | |
log_daemon_msg "$NAME process is not running" | |
log_end_msg 0 | |
fi | |
;; | |
restart) | |
$0 stop && sleep 2 && $0 start | |
;; | |
status) | |
# Check the status of the process. | |
if [ -e $PIDFILE ]; then | |
status_of_proc -p $PIDFILE $DAEMON "$NAME process" && exit 0 || exit $? | |
else | |
log_daemon_msg "$NAME Process is not running" | |
log_end_msg 0 | |
fi | |
;; | |
*) | |
echo "Usage: /etc/init.d/$NAME {start|stop|restart|status}" >&2 | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment