~ubuntu-branches/ubuntu/dapper/asterisk/dapper-security

« back to all changes in this revision

Viewing changes to debian/asterisk-classic.asterisk.init

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2006-05-18 10:21:06 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20060518102106-5vgpbtylsvr9jiu3
Tags: 1:1.2.7.1.dfsg-2ubuntu1
* Resynchronized with Debian, only Ubuntu changes:
  - debian/*.init:
    - create /var/run/ directory if necessary.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
#
 
3
# asterisk      start the asterisk PBX
 
4
# (c) Mark Purcell <msp@debian.org>
 
5
# May be distributed under the terms of this General Public License
 
6
#
 
7
# Based on:
 
8
#
 
9
# skeleton      example file to build /etc/init.d/ scripts.
 
10
#               This file should be used to construct scripts for /etc/init.d.
 
11
#
 
12
#               Written by Miquel van Smoorenburg <miquels@cistron.nl>.
 
13
#               Modified for Debian GNU/Linux
 
14
#               by Ian Murdock <imurdock@gnu.ai.mit.edu>.
 
15
#
 
16
# Version:      @(#)skeleton  1.9  26-Feb-2001  miquels@cistron.nl
 
17
#
 
18
 
 
19
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 
20
NAME=asterisk
 
21
USER=$NAME
 
22
GROUP=$USER
 
23
DAEMON=/usr/sbin/$NAME
 
24
DESC="Asterisk PBX"
 
25
PIDFILE="/var/run/asterisk/asterisk.pid"
 
26
 
 
27
# by default: use real-time priority
 
28
PARAMS=""
 
29
AST_REALTIME="yes"
 
30
RUNASTERISK="no"
 
31
if [ -r /etc/default/$NAME ]; then . /etc/default/$NAME; fi
 
32
 
 
33
if [ "$RUNASTERISK" != "yes" ];then
 
34
        echo "Asterisk not yet configured. Edit /etc/default/asterisk first."
 
35
        exit 0
 
36
fi
 
37
 
 
38
if [ "$AST_REALTIME" != "no" ]
 
39
then
 
40
  PARAMS="$PARAMS -p"
 
41
fi
 
42
 
 
43
if [ "x$USER" = "x" ]
 
44
then
 
45
  echo "Error: empty USER name"
 
46
  exit 1
 
47
fi
 
48
if [ `id -u "$USER"` = 0 ]
 
49
then
 
50
  echo "Starting as root not supported."
 
51
  exit 1
 
52
fi
 
53
PARAMS="$PARAMS -U $USER"
 
54
 
 
55
if [ "x$AST_DEBUG_PARAMS" = x ] 
 
56
then
 
57
  AST_DEBUG_PARAMS=-cvvvvvddddd
 
58
fi
 
59
if [ "$RUNASTSAFE" = "yes" ];then
 
60
        # The value of WRAPPER_DAEMON in can be set in /etc/default/asterisk
 
61
        WRAPPER_DAEMON=${WRAPPER_DAEMON:-/usr/sbin/safe_asterisk}
 
62
        REALDAEMON="$WRAPPER_DAEMON"
 
63
else
 
64
        REALDAEMON="$DAEMON"
 
65
fi
 
66
 
 
67
test -x $DAEMON || exit 0
 
68
 
 
69
set -e
 
70
 
 
71
if [ ! -e `basename $PIDFILE` ];then
 
72
       mkdir `basename $PIDFILE`
 
73
fi
 
74
 
 
75
status() {
 
76
        plist=`ps auxw | grep "$DAEMON" | grep -v grep | awk '{print $2}' | tr '\012' ' '`
 
77
        if [ "$plist" = "" ]; then
 
78
                echo "$DESC is stopped"
 
79
                return 1
 
80
        else
 
81
                echo "$DESC is running: $plist"
 
82
                return 0
 
83
        fi
 
84
}
 
85
 
 
86
case "$1" in
 
87
  debug)
 
88
        # we add too many special parameters that I don't want to skip
 
89
        # accidentally. I'm afraid that skipping -U once may cause
 
90
        # confusing results. I also want to maintain the user's choice
 
91
        # of -p
 
92
        echo "Debugging $DESC: "
 
93
        $DAEMON $PARAMS $AST_DEBUG_PARAMS
 
94
        exit 0
 
95
        ;;
 
96
  start)
 
97
        if status > /dev/null; then
 
98
                echo "$DESC is already running. Use restart."
 
99
                exit 1
 
100
        fi
 
101
        echo -n "Starting $DESC: "
 
102
        if [ "$RUNASTSAFE" != "yes" ];then
 
103
                # TODO: what if we cought the wrapper just as its asterisk
 
104
                # was killed? status should check for the wrapper if we're in
 
105
                # "safe mode"
 
106
                if status > /dev/null; then
 
107
                        echo "$DESC is already running. Use restart."
 
108
                        exit 1
 
109
                fi
 
110
        fi
 
111
        echo -n "Starting $DESC: "
 
112
        start-stop-daemon --start --group $GROUP --pidfile "$PIDFILE" \
 
113
                --exec $REALDAEMON -- $PARAMS
 
114
        echo "$NAME."
 
115
        ;;
 
116
  stop)
 
117
        echo -n "Stopping $DESC: "
 
118
        if [ "$RUNASTSAFE" = "yes" ];then
 
119
                # hopefully this will work. Untested
 
120
                $REALDAEMON -rx 'stop now' > /dev/null  || true
 
121
        else
 
122
                # Try gracefully.
 
123
                # this may hang in some cases. Specifically, when the asterisk
 
124
                # processes is stopped. No bother to worry about cleanup: 
 
125
                # it will either fail or die when asterisk dies.
 
126
                ( $DAEMON -rx 'stop now' > /dev/null 2>&1 & ) &
 
127
        fi
 
128
        echo -n "$NAME"
 
129
        ## giving a small grace time to shut down cleanly.
 
130
        #sleep 2 # you can add timeouts in the comma
 
131
        if [ "$RUNASTSAFE" = "yes" ];then
 
132
                start-stop-daemon --quiet --oknodo --stop --exec $WRAPPER_DAEMON 
 
133
        fi
 
134
        # just making sure it's really, really dead. 
 
135
        # KILL is necessary just in case there's an asterisk -r in the background
 
136
        start-stop-daemon --stop --quiet --oknodo --retry=0/2/TERM/2/KILL/5 --exec $REALDAEMON
 
137
        echo "."
 
138
        ;;
 
139
  reload)
 
140
        echo "Reloading $DESC configuration files."
 
141
        $DAEMON -rx 'reload'
 
142
        ;;
 
143
  logger-reload)
 
144
        $DAEMON -rx 'logger reload'
 
145
        ;;
 
146
  extensions-reload)
 
147
        echo "Reloading $DESC configuration files."
 
148
        $DAEMON -rx 'extensions reload'
 
149
        ;;
 
150
  restart|force-reload)
 
151
        $0 stop
 
152
        $0 start
 
153
        ;;
 
154
  status)
 
155
        status
 
156
        exit $?
 
157
        ;;
 
158
  *)
 
159
        N=/etc/init.d/$NAME
 
160
        # echo "Usage: $N {start|stop|restart|reload|logger-reload|extensions-reload|force-reload}" >&2
 
161
        echo "Usage: $N {start|stop|status|debug|restart|force-reload}" >&2
 
162
        exit 1
 
163
        ;;
 
164
esac
 
165
 
 
166
exit 0