forked from DOMjudge/domjudge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
domjudge-judgehost.init.in
executable file
·115 lines (102 loc) · 2.98 KB
/
domjudge-judgehost.init.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#! /bin/sh
### BEGIN INIT INFO
# Provides: domjudge-judgehost
# Required-Start: $remote_fs $syslog $network
# Required-Stop: $remote_fs $syslog
# Should-Start: $all $network apache2 nginx mysql
# Should-Stop: $all $network apache2 nginx mysql
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: DOMjudge Judgedaemon
### END INIT INFO
#
# SystemV init script to start a judgedaemon.
# In OPTIONS you can configure which CPUset to use when using cgroups.
#
# This is currently very much geared towards Debian(like) systems.
# Improvements for other systems welcome.
NAME=judgedaemon
OPTIONS='-d -v3 -n 0'
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
BINDIR=@judgehost_bindir@
RUNDIR=@judgehost_rundir@
CHROOTDIR=@judgehost_chrootdir@
CGROUPDIR=@judgehost_cgroupdir@
DAEMON=$BINDIR/judgedaemon
PIDFILE=$RUNDIR/$NAME.pid
DESC="DOMjudge Judgedaemon"
RUNAS=@DOMJUDGE_USER@
test -x $DAEMON || exit 0
. /lib/lsb/init-functions
if [ ! -d $RUNDIR ]; then
mkdir -p $RUNDIR
chown $RUNAS $RUNDIR
fi
# Make sure cgroups are mounted where we expect them
if [ ! -d $CGROUPDIR/memory/domjudge ]; then
$BINDIR/create_cgroups
fi
# Check for required cgroup feature
if [ ! -f $CGROUPDIR/memory/domjudge/memory.memsw.limit_in_bytes ]; then
echo "Error: Swapaccounting support missing from cgroups. Unable to continue.
To fix this, please make the following changes:
1. In /etc/default/grub, add 'swapaccount=1' to GRUB_CMDLINE_LINUX_DEFAULT
2. Run update-grub
3. Reboot" >&2
exit 0
fi
# Check that the chroot is created/set up properly
if [ ! -d $CHROOTDIR ]; then
echo "Warning: chroot $CHROOTDIR not created. Run dj_make_chroot or dj_make_ubuntu_chroot to create it."
fi
# Close some file descriptors beyond stdio, because these cannot be
# closed in the judgedaemon PHP script, workaround for Debian postinst
# hanging on open fd.
exec 3>&-
exec 4>&-
exec 5>&-
case "$1" in
start)
log_begin_msg "Starting $DESC: $NAME"
if [ -d $CHROOTDIR ]; then
mount -t proc proc $CHROOTDIR/proc
fi
start-stop-daemon --start --quiet --chuid $RUNAS --pidfile "$PIDFILE" --exec "$DAEMON" -- $OPTIONS
log_end_msg $?
;;
stop)
log_begin_msg "Stopping $DESC: $NAME"
start-stop-daemon --stop --quiet --retry 5 --pidfile $PIDFILE
if [ -d $CHROOTDIR ]; then
umount $CHROOTDIR/proc || true
fi
log_end_msg $?
;;
reload|force-reload|restart)
log_begin_msg "Restarting $DESC: $NAME"
if start-stop-daemon --stop --quiet --retry 5 --pidfile $PIDFILE; then
start-stop-daemon --start --quiet --chuid $RUNAS --pidfile "$PIDFILE" --exec "$DAEMON" -- $OPTIONS
fi
log_end_msg $?
;;
status)
echo -n "Status of $DESC: "
if [ ! -r "$PIDFILE" ]; then
echo "$NAME is not running."
exit 3
fi
if read pid < "$PIDFILE" && ps -p "$pid" > /dev/null 2>&1; then
echo "$NAME is running."
exit 0
else
echo "$NAME is not running but $PIDFILE exists."
exit 1
fi
;;
*)
N=/etc/init.d/${0##*/}
echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
exit 1
;;
esac
exit 0