#!/bin/sh ### BEGIN INIT INFO # Provides: mangosd # Required-Start: $local_fs $remote_fs $network $syslog $named # Required-Stop: $local_fs $remote_fs $network $syslog $named # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # X-Interactive: false # Short-Description: mangosd service ### END INIT INFO #mangosd service MANGOS_USER="mangos" DAEMON=bin/mangosd start() { echo "Starting mangosd..." HOMEDIR=`getent passwd $MANGOS_USER | cut -d: -f6` if [ -x $HOMEDIR/$DAEMON ]; then HOME="$HOMEDIR" start-stop-daemon --start -c $MANGOS_USER --pidfile $HOMEDIR/bin/mangosd.pid --make-pidfile --exec $HOMEDIR/bin/mangosd -d $HOMEDIR/bin --background -- -c $HOMEDIR/etc/mangosd.conf fi } stop() { echo "Stopping mangosd..." HOMEDIR=`getent passwd $MANGOS_USER | cut -d: -f6` if [ -x $HOMEDIR/$DAEMON ]; then start-stop-daemon -o -c $MANGOS_USER -K -u $MANGOS_USER -x $HOMEDIR/$DAEMON fi } status() { dbpid=`pgrep -u $MANGOS_USER mangosd` if [ -z $dbpid ] ; then echo "mangosd for USER $MANGOS_USER: not running." else echo "mangosd for USER $MANGOS_USER: running (pid $dbpid)" fi } case "$1" in start) start ;; stop) stop ;; restart|reload|force-reload) stop start ;; status) status ;; *) echo "Usage: /etc/init.d/mangosd {start|stop|reload|force-reload|restart|status}" exit 1 esac exit 0
Using tmux
to fork a detachable shell in order to access the mangos command line:
[Unit] Description=MaNGoS Zero World Server Requires=network.target local-fs.target remote-fs.target mariadb.service realm0.service After=network.target local-fs.target remote-fs.target mariadb.service realm0.service PartOf=realm0.service [Install] WantedBy=multi-user.target [Service] # Configuration Environment=WORKING_DIRECTORY="/opt/mangos0/" Environment=TMUX_SESSION_NAME="mangos0" # Internals Type=simple KillMode=mixed TimeoutStopSec=60 User=mangos0 ExecStart=/usr/bin/tmux new-session -d -c "$WORKING_DIRECTORY" -s "$TMUX_SESSION_NAME" -n "$TMUX_SESSION_NAME" /opt/mangos0/bin/mangosd -a /opt/mangos0/etc/ahbot.conf -c /opt/mangos0/etc/mangosd.conf ExecStop=/usr/bin/tmux send-keys -t "$TMUX_SESSION_NAME" C-c RemainAfterExit=yes