-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathuwsgi_service-debian.erb
More file actions
183 lines (156 loc) · 4.76 KB
/
uwsgi_service-debian.erb
File metadata and controls
183 lines (156 loc) · 4.76 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/bash
### BEGIN INIT INFO
# Provides: uwsgi
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop uWSGI server instance(s)
# Description: This script manages uWSGI server instance(s).
# You could control specific instance(s) by issuing:
#
# service uwsgi <command> <confname> <confname> ...
#
# You can issue to init.d script following commands:
# * start | starts daemon
# * stop | stops daemon
# * reload | sends to daemon SIGHUP signal
# * restart | issues 'stop', then 'start' commands
# * status | shows status of daemon instance
#
# 'status' command must be issued with exactly one
# argument: '<confname>'.
#
# In init.d script output:
# * . -- command was executed without problems or instance
# is already in needed state
# * ! -- command failed (or executed with some problems)
# * ? -- configuration file for this instance isn't found
# and this instance is ignored
#
### END INIT INFO
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
DESC="app server(s)"
NAME="uwsgi"
DAEMON="/usr/local/bin/uwsgi"
SCRIPTNAME="/etc/init.d/${NAME}"
UWSGI_CONFDIR="<%= @app_directory %>"
PIDFILE="<%= @pidfile %>"
UWSGI_RUNDIR="${PIDFILE%/*}"
UWSGI_LOGDIR="<%= @log_file %>%/*"
DAEMON_OPTS="--ini "<%= @config_file %>" "
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Create directory if not created
[ -d "$UWSGI_CONFDIR" ] || mkdir -p $UWSGI_CONFDIR
[ -d "$UWSGI_RUNDIR" ] || mkdir -p $UWSGI_RUNDIR
[ -d "$UWSGI_LOGDIR" ] || mkdir -p $UWSGI_LOGDIR
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
# This is shell script, (indirectly) sourced by uWSGI init.d script
# Return:
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
do_start()
{
local CONFFILE=<%= @config_file %>
if [ ! -s "$CONFFILE" ]; then
return 2
fi
install -d -o root -g root -m 755 "${UWSGI_RUNDIR}"
start-stop-daemon --start --quiet \
--pidfile "$PIDFILE" \
--exec "$DAEMON" \
--test > /dev/null \
|| return 1
start-stop-daemon --start --quiet \
--pidfile $PIDFILE \
--exec $DAEMON -- $DAEMON_OPTS > /dev/null \
|| return 2
sleep 2
chown root:root "$PIDFILE"
chmod 644 "$PIDFILE"
start-stop-daemon --start --quiet \
--pidfile "$PIDFILE" \
--exec "$DAEMON" \
--test > /dev/null \
&& return 2
return 0
}
# Return:
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
do_stop()
{
start-stop-daemon --stop --quiet \
--retry=QUIT/30/KILL/5 \
--pidfile "$PIDFILE" \
--name "$NAME"
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
return "$RETVAL"
}
# Return:
# 0 if daemon has been reloaded
# 3 if daemon could not be reloaded
do_reload()
{
start-stop-daemon --stop --quiet \
--signal=HUP \
--pidfile "$PIDFILE" \
--name "$NAME"
RETVAL="$?"
# There is no such process, nothing to reload!
[ "$RETVAL" = 1 ] && RETVAL=3
return "$RETVAL"
}
WHAT=$1
case "$WHAT" in
start)
log_daemon_msg "Starting $DESC" "$NAME"
do_"$WHAT"
RETVAL="$?"
log_end_msg "$RETVAL"
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
do_"$WHAT"
RETVAL="$?"
log_end_msg "$RETVAL"
;;
status)
status_of_proc -p "$PIDFILE" "$DAEMON" "$NAME" \
&& exit 0 \
|| exit $?
;;
reload)
log_daemon_msg "Reloading $DESC" "$NAME"
do_"$WHAT"
RETVAL="$?"
log_end_msg "$RETVAL"
;;
restart)
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0)
do_start
RETVAL="$?"
log_end_msg "$RETVAL"
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart|reload}" >&2
exit 3
;;
esac