-
Notifications
You must be signed in to change notification settings - Fork 54
Debian service
Alexandre Girard edited this page Nov 12, 2013
·
1 revision
Here is a tutorial about running echoplexus on your computer/server as a Debian service.
Echoplexus is running on debian, using echoplexus user, and the git clone is inside /home/echoplexus/echoplexus
Your current installation should be working before configuring this service.
I've created a small start_echoplexus.sh
script in /home/echoplexus
, containing :
#!/bin/sh
cd $HOME/echoplexus
npm start
Don't forget to make this script executable : chmod +x /home/echoplexus/start_echoplexus.sh
Then, I've create a script in /etc/init.d/echoplexus
, containing :
#!/bin/sh
### BEGIN INIT INFO
# Provides: echoplexus
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts echoplexus
# Description: starts echoplexus using start-stop-daemon
### END INIT INFO
PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/node/bin"
LOGFILE="/var/log/echoplexus.log"
ECHOPLEXUS_BIN="/home/echoplexus/start_echoplexus.sh"
USER="echoplexus"
GROUP="echoplexus"
DESC="Echoplexus"
NAME="echoplexus"
set -e
. /lib/lsb/init-functions
start() {
echo "Starting $DESC... "
start-stop-daemon --start --chuid "$USER:$GROUP" --background --make-pidfile --pidfile /var/run/$NAME.pid --exec $ECHOPLEXUS_BIN -- $LOGFILE || true
echo "done"
}
#We need this function to ensure the whole process tree will be killed
killtree() {
local _pid=$1
local _sig=${2-TERM}
for _child in $(ps -o pid --no-headers --ppid ${_pid}); do
killtree ${_child} ${_sig}
done
kill -${_sig} ${_pid}
}
stop() {
echo "Stopping $DESC... "
while test -d /proc/$(cat /var/run/$NAME.pid); do
killtree $(cat /var/run/$NAME.pid) 15
sleep 0.5
done
rm /var/run/$NAME.pid
echo "done"
}
status() {
status_of_proc -p /var/run/$NAME.pid "" "echoplexus" && exit 0 || exit $?
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
*)
echo "Usage: $NAME {start|stop|restart|status}" >&2
exit 1
;;
esac
exit 0
Then you just need to update your rc.d :
update-rc.d echoplexus defaults
Then just start echoplexus with this command :
/etc/init.d/echoplexus start
Echoplexus will be started each time your start your computer/server.