source: scripts/etc/init.d/7dtd.sh@ 5

Last change on this file since 5 was 1, checked in by alloc, 11 years ago

Initial commit

  • Property svn:executable set to *
File size: 2.4 KB
RevLine 
[1]1#!/bin/sh
2
3### BEGIN INIT INFO
4# Provides: 7dtd-server
5# Required-Start: $remote_fs
6# Required-Stop: $remote_fs
7# Should-Start: $named
8# Should-Stop: $named
9# Default-Start: 2 3 4 5
10# Default-Stop: 0 1 6
11# Short-Description: 7 Days to Die server
12# Description: Starts a 7 Days to Die server
13### END INIT INFO
14
15. /etc/7dtd.conf
16
17NAME="7DtD"
18SCREENREF="sdtd"
19BINARYPATH=$SDTD_ROOT
20USER=$SDTD_USER
21RUNTIME=$WINE
22BINARYNAME=7DaysToDie.exe
23PIDFILE="7dtd-server.pid"
24
25OPTS="-quit -batchmode -nographics -configfile=../serverconfig.xml -dedicated"
26
27cd "$BINARYPATH"
28
29case "$1" in
30 start)
31 echo -n "Starting the $NAME server... "
32 if [ ! `pgrep Xvfb` ]; then
33 su -c "/usr/bin/Xvfb :1 -screen 0 640x480x16" sdtd &
34 sleep 3
35 fi
36 if [ -e "$BINARYNAME" ]; then
37 if [ `pgrep $BINARYNAME` ]; then
38 echo "Already running!"
39 else
40 export DISPLAY=localhost:1.0
41 start-stop-daemon --start --pidfile $SDTD_ROOT/$PIDFILE --background --make-pidfile --chuid $USER --user $USER --chdir $BINARYPATH --exec "/usr/bin/screen" -- -D -m -S $SCREENREF $RUNTIME $BINARYPATH/$BINARYNAME $OPTS
42 sleep 1
43 fi
44 else
45 echo "Could not find binary, aborting!"
46 exit 5
47 fi
48 if [ `pgrep -F $SDTD_ROOT/$PIDFILE` ]; then
49 echo "Done!"
50 else
51 echo "Failed!"
52 rm -f $SDTD_ROOT/$PIDFILE
53 fi
54 ;;
55 stop)
56 start-stop-daemon --status --pidfile $SDTD_ROOT/$PIDFILE
57 if [ $? -eq 0 ]; then
58 echo -n "Stopping the $NAME server... "
59 if [ "$SDTD_TELNET_ENABLED" = "true" ] && [ -n "$SDTD_TELNET_PASSWORD" ]; then
60 echo "$SDTD_TELNET_PASSWORD\nshutdown" | nc -q 2 127.0.0.1 $SDTD_TELNET_PORT
61 sleep 5
62 else
63 echo "Telnet not enabled or no password set. No graceful shutdown!"
64 fi
65 start-stop-daemon --stop --pidfile $SDTD_ROOT/$PIDFILE
66 rm $SDTD_ROOT/$PIDFILE
67 echo "Done!"
68 else
69 echo "$NAME not running"
70 fi
71 ;;
72 status)
73 start-stop-daemon --status --pidfile $SDTD_ROOT/$PIDFILE
74 if [ $? -eq 0 ]; then
75 echo "$NAME server is running"
76 else
77 echo "$NAME server not running"
78 fi
79 ;;
80 *)
81 echo "Usage: ${0} {start|stop|status}"
82 exit 2
83esac
84exit 0
Note: See TracBrowser for help on using the repository browser.