~ubuntu-branches/ubuntu/quantal/python-django/quantal

« back to all changes in this revision

Viewing changes to debian/contrib/initscript

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2009-07-29 11:26:28 UTC
  • mfrom: (1.1.8 upstream) (4.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20090729112628-pg09ino8sz0sj21t
Tags: 1.1-1
* New upstream release.
* Merge from experimental:
  - Ship FastCGI initscript and /etc/default file in python-django's examples
    directory (Closes: #538863)
  - Drop "05_10539-sphinx06-compatibility.diff"; it has been applied
    upstream.
  - Bump Standards-Version to 3.8.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
### BEGIN INIT INFO
 
3
# Provides:          FastCGI servers for Django
 
4
# Required-Start:    networking
 
5
# Required-Stop:     networking
 
6
# Default-Start:     2 3 4 5
 
7
# Default-Stop:      S 0 1 6
 
8
# Short-Description: Start FastCGI servers with Django.
 
9
# Description:       Django, in order to operate with FastCGI, must be started
 
10
#                    in a very specific way with manage.py. This must be done
 
11
#                    for each Django web server that has to run.
 
12
### END INIT INFO
 
13
#
 
14
# Author:  Guillermo Fernandez Castellanos
 
15
#          <guillermo.fernandez.castellanos AT gmail.com>.
 
16
#
 
17
# Changed: Jannis Leidel
 
18
#          <jannis AT leidel.info>
 
19
#          Joost Cassee
 
20
#          <joost@cassee.net>
 
21
#
 
22
# Version: @(#)fastcgi 0.3 05-Aug-2008 joost AT cassee.net
 
23
#
 
24
 
 
25
set -e
 
26
 
 
27
#### CONFIGURATION (override in /etc/default/django)
 
28
 
 
29
# django project names/directories
 
30
DJANGO_SITES=""
 
31
 
 
32
# path to the directory with your django projects
 
33
SITES_PATH=/var/lib/django
 
34
 
 
35
# path to the directory for socket and pid files
 
36
RUNFILES_PATH=/var/run/django
 
37
 
 
38
# please make sure this is NOT root
 
39
# local user prefered, www-data accepted
 
40
RUN_AS=www-data
 
41
 
 
42
# maximum requests before fast-cgi process respawns
 
43
# (a.k.a. get killed and let live)
 
44
MAXREQUESTS=1000
 
45
 
 
46
#### END CONFIGURATION
 
47
 
 
48
# Include defaults if available
 
49
if [ -f /etc/default/django ] ; then
 
50
    . /etc/default/django
 
51
fi
 
52
 
 
53
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 
54
DESC="Django FastCGI servers"
 
55
NAME=$0
 
56
SCRIPTNAME=/etc/init.d/$NAME
 
57
mkdir -p $RUNFILES_PATH
 
58
chown -R $RUN_AS:$RUN_AS $RUNFILES_PATH
 
59
 
 
60
#
 
61
#       Function that starts the daemon/service.
 
62
#
 
63
d_start()
 
64
{
 
65
    # Starting all Django FastCGI processes
 
66
    # PORT=$PORT_START
 
67
    for SITE in $DJANGO_SITES
 
68
    do
 
69
        echo -n ", $SITE"
 
70
        if [ -f $RUNFILES_PATH/$SITE.pid ]; then
 
71
            echo -n " already running"
 
72
        else
 
73
            start-stop-daemon --start --quiet \
 
74
                       --pidfile $RUNFILES_PATH/$SITE.pid \
 
75
                       --chuid $RUN_AS --exec /usr/bin/env -- python \
 
76
                       $SITES_PATH/$SITE/manage.py runfcgi \
 
77
                       protocol=fcgi method=threaded maxrequests=$MAXREQUESTS \
 
78
                       socket=$RUNFILES_PATH/$SITE.socket \
 
79
                       pidfile=$RUNFILES_PATH/$SITE.pid
 
80
            chmod 400 $RUNFILES_PATH/$SITE.pid
 
81
        fi
 
82
        sleep 1
 
83
    done
 
84
}
 
85
 
 
86
#
 
87
#       Function that stops the daemon/service.
 
88
#
 
89
d_stop() {
 
90
    # Killing all Django FastCGI processes running
 
91
    for SITE in $DJANGO_SITES
 
92
    do
 
93
        echo -n ", $SITE"
 
94
        start-stop-daemon --stop --quiet --pidfile $RUNFILES_PATH/$SITE.pid \
 
95
                          || echo -n " not running"
 
96
        if [ -f $RUNFILES_PATH/$SITE.pid ]; then
 
97
           rm -f $RUNFILES_PATH/$SITE.pid
 
98
        fi
 
99
        sleep 1
 
100
    done
 
101
}
 
102
 
 
103
ACTION="$1"
 
104
case "$ACTION" in
 
105
    start)
 
106
        echo -n "Starting $DESC: $NAME"
 
107
        d_start
 
108
        echo "."
 
109
        ;;
 
110
 
 
111
    stop)
 
112
        echo -n "Stopping $DESC: $NAME"
 
113
        d_stop
 
114
        echo "."
 
115
        ;;
 
116
 
 
117
    restart|force-reload)
 
118
        echo -n "Restarting $DESC: $NAME"
 
119
        d_stop
 
120
        sleep 2
 
121
        d_start
 
122
        echo "."
 
123
        ;;
 
124
 
 
125
    *)
 
126
        echo "Usage: $NAME {start|stop|restart|force-reload}" >&2
 
127
        exit 3
 
128
        ;;
 
129
esac
 
130
 
 
131
exit 0