-
Notifications
You must be signed in to change notification settings - Fork 176
/
ubuntu.initd
executable file
·150 lines (123 loc) · 3.97 KB
/
ubuntu.initd
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#! /bin/sh
# Copyright (C) 2011- by Mar2zz <LaSi.Mar2zz@gmail.com>
# released under GPL, version 2 or later
################################################
# #
# TO CONFIGURE EDIT /etc/default/lazylibrarian
# #
################################################
### BEGIN INIT INFO
# Provides: LazyLibrarian application instance
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts instance of LazyLibrarian
# Description: starts instance of LazyLibrarian using start-stop-daemon
### END INIT INFO
# main variables
DAEMON=/usr/bin/python
SETTINGS=/etc/default/lazylibrarian
SETTINGS_LOADED=FALSE
DESC=LazyLibrarian
# only accept values from /etc/default/lazylibrarian
unset RUN_AS CONFIG DATADIR PID_FILE
. /lib/lsb/init-functions
[ -x $DAEMON ] || {
log_warning_msg "$DESC: Can't execute daemon, aborting. See $DAEMON";
return 1; }
[ -r $SETTINGS ] || {
log_warning_msg "$DESC: Can't read settings, aborting. See $SETTINGS";
return 1; }
check_retval() {
if [ $? -eq 0 ]; then
log_end_msg 0
return 0
else
log_end_msg 1
exit 1
fi
}
load_settings() {
if [ $SETTINGS_LOADED != "TRUE" ]; then
. $SETTINGS
[ -n "$APP_PATH" ] || {
log_warning_msg "$DESC: path to $DESC not set, aborting. See $SETTINGS";
return 1; }
[ $ENABLE_DAEMON != 1 ] && {
log_warning_msg "$DESC: daemon not enabled, aborting. See $SETTINGS";
return 1; }
[ -z "$RUN_AS" ] && {
log_warning_msg "$DESC: daemon username not set, aborting. See $SETTINGS";
return 1; }
[ -z "${RUN_AS%:*}" ] && exit 1
DAEMON_OPTS="LazyLibrarian.py --quiet -d --nolaunch"
[ -n "$CONFIG" ] && DAEMON_OPTS="$DAEMON_OPTS --config=$CONFIG"
[ -z "$CONFIG" ] && DAEMON_OPTS="$DAEMON_OPTS --config=/home/$RUN_AS/.lazylibrarian/config.ini"
[ -n "$DATADIR" ] && DAEMON_OPTS="$DAEMON_OPTS --datadir=$DATADIR"
[ -z "$DATADIR" ] && DAEMON_OPTS="$DAEMON_OPTS --datadir=/home/$RUN_AS/.lazylibrarian"
[ -n "$PORT" ] && DAEMON_OPTS="$DAEMON_OPTS --port=$PORT"
if ! [ -n "$PID_FILE" ]; then
PID_FILE=/var/run/lazylibrarian/lazylibrarian.pid
fi
DAEMON_OPTS="$DAEMON_OPTS --pidfile=$PID_FILE"
SETTINGS_LOADED=TRUE
fi
return 0
}
load_settings || exit 0
is_running () {
# returns 1 when running, else 0.
PID=$(pgrep -f "$DAEMON_OPTS")
RET=$?
[ $RET -gt 1 ] && exit 1 || return $RET
}
handle_pid () {
PID_PATH=`dirname $PID_FILE`
[ -d $PID_PATH ] || mkdir -p $PID_PATH && chown -R $RUN_AS $PID_PATH > /dev/null || {
log_warning_msg "$DESC: Could not create $PID_FILE, aborting.";
return 1;}
}
enable_updates () {
chown -R $RUN_AS $APP_PATH > /dev/null || {
log_warning_msg "$DESC: $APP_PATH not writable for web-updates, See $SETTINGS";
return 0; }
}
start_lazylibrarian () {
if ! is_running; then
log_daemon_msg "Starting $DESC"
[ "$WEB_UPDATE" = 1 ] && enable_updates
handle_pid
start-stop-daemon -o -d $APP_PATH -c $RUN_AS --start --pidfile $PID_FILE --exec $DAEMON -- $DAEMON_OPTS
check_retval
else
log_success_msg "$DESC: already running (pid $PID)"
fi
}
stop_lazylibrarian () {
if is_running; then
log_daemon_msg "Stopping $DESC"
start-stop-daemon -o --stop --pidfile $PID_FILE --retry 15
check_retval
else
log_success_msg "$DESC: not running"
fi
}
case "$1" in
start)
start_lazylibrarian
;;
stop)
stop_lazylibrarian
;;
restart|force-reload)
stop_lazylibrarian
start_lazylibrarian
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0