Project

General

Profile

Download (4.78 KB) Statistics
| Branch: | Tag: | Revision:

root / debian / u-auth.init @ 75a981d9

1
#!/bin/sh
2
### BEGIN INIT INFO
3
# Provides:          u-auth
4
# Required-Start:    $network $local_fs
5
# Required-Stop:
6
# Default-Start:     2 3 4 5
7
# Default-Stop:      0 1 6
8
# Short-Description: Captive portal in the Cloud
9
# Description:       Captive portal in the Cloud
10
### END INIT INFO
11

    
12
# Author:  Entr'ouvert <info@entrouvert.com>
13

    
14
PATH=/sbin:/usr/sbin:/bin:/usr/bin
15
DESC="Captive portal in the Cloud"
16
NAME=u-auth
17
DAEMON=/usr/bin/gunicorn
18
RUN_DIR=/run/$NAME
19
PIDFILE=$RUN_DIR/$NAME.pid
20
LOG_DIR=/var/log/$NAME
21
SCRIPTNAME=/etc/init.d/$NAME
22
BIND=unix:$RUN_DIR/$NAME.sock
23
WORKERS=5
24
TIMEOUT=30
25

    
26
UAUTH_SETTINGS_FILE=/usr/lib/$NAME/debian_config.py
27
MANAGE_SCRIPT="/usr/bin/$NAME-manage"
28

    
29
USER=$NAME
30
GROUP=$NAME
31

    
32
# Exit if the package is not installed
33
[ -x $MANAGE_SCRIPT ] || exit 0
34

    
35
# Read configuration variable file if it is present
36
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
37

    
38
DAEMON_ARGS=${DAEMON_ARGS:-"--pid $PIDFILE \
39
--user $USER --group $GROUP \
40
--daemon \
41
--access-logfile $LOG_DIR/gunicorn-access.log \
42
--log-file $LOG_DIR/gunicorn-error.log \
43
--bind=$BIND  \
44
--workers=$WORKERS \
45
--worker-class=sync \
46
--timeout=$TIMEOUT \
47
--name $NAME \
48
uauth.wsgi:application"}
49

    
50
# Load the VERBOSE setting and other rcS variables
51
. /lib/init/vars.sh
52

    
53
# Define LSB log_* functions.
54
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
55
. /lib/lsb/init-functions
56

    
57
# Create /run directory
58
if [ ! -d $RUN_DIR ]; then
59
    install -d -m 755 -o $USER -g $GROUP $RUN_DIR
60
fi
61

    
62
# environment for wsgi
63
export UAUTH_SETTINGS_FILE
64

    
65
#
66
# Function that starts the daemon/service
67
#
68
do_start()
69
{
70
    # Return
71
    #   0 if daemon has been started
72
    #   1 if daemon was already running
73
    #   2 if daemon could not be started
74
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
75
        || return 1
76
    start-stop-daemon --start --quiet --exec $DAEMON -- \
77
        $DAEMON_ARGS \
78
        || return 2
79
}
80

    
81
#
82
# Function that stops the daemon/service
83
#
84
do_stop()
85
{
86
    # Return
87
    #   0 if daemon has been stopped
88
    #   1 if daemon was already stopped
89
    #   2 if daemon could not be stopped
90
    #   other if a failure occurred
91
    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
92
    RETVAL="$?"
93
    [ "$RETVAL" = 2 ] && return 2
94
    # Wait for children to finish too if this is a daemon that forks
95
    # and if the daemon is only ever run from this initscript.
96
    # If the above conditions are not satisfied then add some other code
97
    # that waits for the process to drop all resources that could be
98
    # needed by services started subsequently.  A last resort is to
99
    # sleep for some time.
100
    start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
101
    [ "$?" = 2 ] && return 2
102
    # Many daemons don't delete their pidfiles when they exit.
103
    rm -f $PIDFILE
104
    return "$RETVAL"
105
}
106

    
107
#
108
# Function that sends a SIGHUP to the daemon/service
109
#
110
do_reload() {
111
    #
112
    # If the daemon can reload its configuration without
113
    # restarting (for example, when it is sent a SIGHUP),
114
    # then implement that here.
115
    #
116
    start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name `basename $DAEMON`
117
    return 0
118
}
119

    
120
do_migrate() {
121
    log_action_msg "Applying migrations (migrate).."
122
    su $USER -p -c "$MANAGE_SCRIPT migrate"
123
    log_action_msg "done"
124
}
125

    
126
do_collectstatic() {
127
    log_action_msg "Collect static files (collectstatic).."
128
    su $USER -p -c "$MANAGE_SCRIPT collectstatic --noinput"
129
    log_action_msg "done"
130
}
131

    
132
case "$1" in
133
  start)
134
    log_daemon_msg "Starting $DESC " "$NAME"
135
    do_migrate
136
    do_collectstatic
137
    do_start
138
    case "$?" in
139
        0|1) log_end_msg 0 ;;
140
        2) log_end_msg 1 ;;
141
    esac
142
  ;;
143
  stop)
144
    log_daemon_msg "Stopping $DESC" "$NAME"
145
    do_stop
146
    case "$?" in
147
        0|1) log_end_msg 0 ;;
148
        2) log_end_msg 1 ;;
149
    esac
150
    ;;
151
  status)
152
    status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
153
    ;;
154
  reload|force-reload)
155
    #
156
    # If do_reload() is not implemented then leave this commented out
157
    # and leave 'force-reload' as an alias for 'restart'.
158
    #
159
    log_daemon_msg "Reloading $DESC" "$NAME"
160
    do_collectstatic
161
    do_migrate
162
    do_reload
163
    log_end_msg $?
164
    ;;
165
  restart|force-reload)
166
    #
167
    # If the "reload" option is implemented then remove the
168
    # 'force-reload' alias
169
    #
170
    log_daemon_msg "Restarting $DESC" "$NAME"
171
    do_stop
172
    case "$?" in
173
      0|1)
174
        do_migrate
175
        do_collectstatic
176
        do_start
177
        case "$?" in
178
            0) log_end_msg 0 ;;
179
            1) log_end_msg 1 ;; # Old process is still running
180
            *) log_end_msg 1 ;; # Failed to start
181
        esac
182
        ;;
183
      *)
184
        # Failed to stop
185
        log_end_msg 1
186
        ;;
187
    esac
188
    ;;
189
  *)
190
    echo "Usage: $SCRIPTNAME {start|stop|status|restart|reload|force-reload}" >&2
191
    exit 3
192
    ;;
193
esac
(14-14/16)