Projet

Général

Profil

Télécharger (4,96 ko) Statistiques
| Branche: | Tag: | Révision:

root / debian / corbo.init @ e090253d

1
#!/bin/sh
2
### BEGIN INIT INFO
3
# Provides:          corbo
4
# Required-Start:    $network $local_fs $remote_fs $syslog
5
# Required-Stop:     $network $local_fs $remote_fs $syslog
6
# Should-start:      postgresql
7
# Should-stop:       postgresql
8
# Default-Start:     2 3 4 5
9
# Default-Stop:      0 1 6
10
# Short-Description: Announces Manager
11
# Description:       Announces Manager
12
### END INIT INFO
13

    
14
# Author:  Serghei Mihai <smihai@entrouvert.com>
15

    
16
PATH=/sbin:/usr/sbin:/bin:/usr/bin
17
DESC="Announces Manager"
18
NAME=corbo
19
DAEMON=/usr/bin/gunicorn
20
RUN_DIR=/run/$NAME
21
PIDFILE=$RUN_DIR/$NAME.pid
22
LOG_DIR=/var/log/$NAME
23
SCRIPTNAME=/etc/init.d/$NAME
24
BIND=unix:$RUN_DIR/$NAME.sock
25
WORKERS=5
26
TIMEOUT=30
27
LOG_LEVEL=debug
28

    
29
CORBO_SETTINGS_FILE=/usr/lib/$NAME/debian_config.py
30
MANAGE_SCRIPT="/usr/bin/$NAME-manage"
31

    
32
USER=$NAME
33
GROUP=$NAME
34

    
35
# Exit if the package is not installed
36
[ -x $MANAGE_SCRIPT ] || exit 0
37

    
38
# Read configuration variable file if it is present
39
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
40

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

    
54
# Load the VERBOSE setting and other rcS variables
55
. /lib/init/vars.sh
56

    
57
# Define LSB log_* functions.
58
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
59
. /lib/lsb/init-functions
60

    
61
# Create /run directory
62
if [ ! -d $RUN_DIR ]; then
63
    install -d -m 755 -o $USER -g $GROUP $RUN_DIR
64
fi
65

    
66
# environment for wsgi
67
export CORBO_SETTINGS_FILE
68

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

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

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

    
124
do_migrate() {
125
    log_action_msg "Applying migrations (migrate_schemas).."
126
    su $USER -s /bin/sh -p -c "$MANAGE_SCRIPT migrate_schemas"
127
    log_action_msg "done"
128
}
129

    
130
do_collectstatic() {
131
    log_action_msg "Collect static files (collectstatic).."
132
    su $USER -s /bin/sh -p -c "$MANAGE_SCRIPT collectstatic --noinput"
133
    log_action_msg "done"
134
}
135

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