forked from alexanderrichard/queueing-tool
-
Notifications
You must be signed in to change notification settings - Fork 1
/
qserver_daemon
executable file
·101 lines (90 loc) · 2.75 KB
/
qserver_daemon
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
#! /bin/sh
### BEGIN INIT INFO
# Provides: queue
# Required-Start: networking
# Required-Stop: networking
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start the queue server.
# Description:
### END INIT INFO
### start qserver automatically at boot:
### place this file into /etc/init.d, then
### sudo update-rc.d qserver_daemon defaults
### TODO: adjust these values to your needs
### QSERVER EXECUTABLE ###
QSERVER_EXECUTABLE=/home/richard/pyqueue/queue/qserver
### QSERVER OPTIONS ###
DEVICE_IDS="0,1" # Cuda device ids, set to empty string if no GPUs available
THREADS=8 # number of available threads
MEMORY=30000 # available memory in mb
ABORT_ON_TIME_LIMIT="true" # abort jobs if time limit is exceeded?
PORT=1234 # port the server listens on
##########################
DAEMON_OPTS="--gpus=$DEVICE_IDS --threads=$THREADS --memory=$MEMORY --port=$PORT"
if [ "$ABORT_ON_TIME_LIMIT" = "true" ]; then
DAEMON_OPTS="$DAEMON_OPTS --abort_on_time_limit"
fi
# Using the lsb functions to perform the operations.
. /lib/lsb/init-functions
# Process name ( For display )
NAME=qserverd
# Daemon name, where is the actual executable
DAEMON=$QSERVER_EXECUTABLE
# pid file for the daemon
PIDFILE=/var/run/qserverd.pid
test -x $DEAMON || exit 1
case "$1" in
start)
if [ -e $PIDFILE ]; then
status_of_proc -p $PIDFILE $DAEMON "$NAME process" && status="0" || status="$?"
if [ $status = "0" ]; then
exit
fi
fi
# start qserverd
log_daemon_msg "Starting the process" "$NAME"
if start-stop-daemon --start -b --make-pidfile --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPTS ; then
log_end_msg 0
else
log_end_msg 1
fi
;;
stop)
# stop qserverd
if [ -e $PIDFILE ]; then
status_of_proc -p $PIDFILE $DAEMON "Stopping the $NAME process" && status="0" || status="$?"
if [ "$status" = 0 ]; then
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
/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)
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
;;
reload)
if [ -e $PIDFILE ]; then
start-stop-daemon --stop --signal USR1 --quiet --pidfile $PIDFILE --name $NAME
log_success_msg "$NAME process reloaded successfully"
else
log_failure_msg "$PIDFILE does not exists"
fi
;;
*)
echo "Usage: $0 {start|stop|restart|reload|status}"
exit 2
;;
esac
: