~ubuntu-branches/ubuntu/raring/maradns/raring

« back to all changes in this revision

Viewing changes to debian/maradns.init

  • Committer: Bazaar Package Importer
  • Author(s): Nicholas Bamber
  • Date: 2011-07-18 12:57:54 UTC
  • mfrom: (10.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20110718125754-7x4bp0qvs8q60s4n
Tags: 1.4.06-3
* Made duende more generic and Debian compatible
  - Added patch to use argp to parse arguments
  - Added support for --pid, --uid, --chroot, --ident, --restart_on,
    and --gid arguments
  - Put log helper process in chroot
  - Write pid of log helper process to syslog
  - Consolidated waitpid calls so to avoid race condition allowing zombies
  - Adjusted section and priority, cf. #632337
  - Added example to show how to use duende generically
  - Added patch to man page documenting changes to duende
* Rewrote maradns init script to use new duende features
  - Init script now relatively standard apart from use of duende and 
    support for multiple servers
  - Reload action in maradns script now sends signal to duende which
    restarts maradns process (Closes: #484466)
  - Added Recommends clause for maradns-zoneserver
* Added comment about #621833 in postrm script and ensured complete removal
  of /etc/maradns directory
* Added maradns-zoneserver package (Closes: #582069)
  - Note that the reload action is not supported for zoneserver
* Updated python support
* Updated TODO.Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
PATH=/sbin:/usr/sbin:/bin:/usr/bin
19
19
DESC="domain name server"
20
20
NAME=maradns
21
 
DAEMON=/usr/share/maradns/$NAME-svr
22
 
LOG_DAEMON=/usr/share/maradns/$NAME-log
 
21
DAEMON=/usr/sbin/$NAME
 
22
DUENDE=/usr/sbin/duende
23
23
SCRIPTNAME=/etc/init.d/$NAME
24
24
WORKING_DIR=/var/run/$NAME
 
25
UID=`id --user maradns`
 
26
GID=`id --group maradns`
25
27
 
26
28
# It is possible to have more than one maradns server
27
29
# running on the same machine so long as they bind to different IP
44
46
. /lib/lsb/init-functions
45
47
 
46
48
#
47
 
# Function that starts the logger
48
 
#
49
 
do_start_logger()
50
 
{
51
 
 
52
 
        # Return
53
 
        #   0 if daemon has been started
54
 
        #   1 if daemon was already running
55
 
        #   2 if daemon could not be started
56
 
 
57
 
        # Make sure fifo pipe between server and logger is up
58
 
        PIPE="$WORKING_DIR/$SERVERNAME.fifo"
59
 
        [ -p $PIPE ] || mkfifo --mode 240 $PIPE || return 2
60
 
        chown maradns:root $PIPE 
61
 
 
62
 
        # Now start the logger
63
 
        LOG_PIDFILE="$WORKING_DIR/$SERVERNAME-log.pid"
64
 
        start-stop-daemon --start --quiet --pidfile $LOG_PIDFILE --exec $LOG_DAEMON --test > /dev/null || return 1
65
 
        start-stop-daemon --make-pidfile --background --start --quiet --pidfile $LOG_PIDFILE --exec $LOG_DAEMON -- $SERVERNAME
66
 
        sleep 1
67
 
        if ! pidofproc -p $LOG_PIDFILE > /dev/null
68
 
        then
69
 
            rm -rf $LOG_PIDFILE
70
 
            return 2
71
 
        fi
72
 
}
73
 
 
74
 
#
75
49
# Function that starts the daemon/service
76
50
#
77
 
do_start_daemon()
 
51
do_start()
78
52
{
79
53
 
80
54
        # Return
85
59
        # Now start the actual maradns process
86
60
        PIDFILE="$WORKING_DIR/$SERVERNAME.pid"
87
61
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null || return 1
88
 
        start-stop-daemon --make-pidfile --background --start --quiet --pidfile $PIDFILE --exec $DAEMON -- $SERVERNAME $rcfile
 
62
        start-stop-daemon --start --quiet --background --pidfile $PIDFILE --startas $DUENDE -- --pid $PIDFILE --uid $UID --gid $GID --ident $SERVERNAME -- $DAEMON -f $rcfile
89
63
        sleep 3
90
64
        if ! pidofproc -p $PIDFILE > /dev/null
91
65
        then
97
71
#
98
72
# Function that stops the daemon/service
99
73
#
100
 
do_stop_daemon()
 
74
do_stop()
101
75
{
102
76
        # Return
103
77
        #   0 if daemon has been stopped
105
79
        #   2 if daemon could not be stopped
106
80
        #   other if a failure occurred
107
81
        PIDFILE="$WORKING_DIR/$SERVERNAME.pid"
108
 
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
 
82
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name duende
109
83
        RETVAL="$?"
110
84
        [ "$RETVAL" = 2 ] && return 2
111
85
        # Many daemons don't delete their pidfiles when they exit.
114
88
}
115
89
 
116
90
#
117
 
# Function that stops the logger
 
91
# Function that sends a SIGHUP to the daemon/service
118
92
#
119
 
do_stop_logger()
120
 
{
121
 
        # Return
122
 
        #   0 if daemon has been stopped
123
 
        #   1 if daemon was already stopped
124
 
        #   2 if daemon could not be stopped
125
 
        #   other if a failure occurred
126
 
        PIDFILE="$WORKING_DIR/$SERVERNAME-log.pid"
127
 
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $LOG_PIDFILE --name $NAME
128
 
        RETVAL="$?"
129
 
        [ "$RETVAL" = 2 ] && return 2
130
 
 
131
 
        # Many daemons don't delete their pidfiles when they exit.
132
 
        rm -f $PIDFILE
133
 
 
134
 
        # Remove the pipe as well
135
 
        rm -f "$WORKING_DIR/$SERVERNAME.fifo"
136
 
 
137
 
        return "$RETVAL"
 
93
do_reload() {
 
94
        #
 
95
        # If the daemon can reload its configuration without
 
96
        # restarting (for example, when it is sent a SIGHUP),
 
97
        # then implement that here.
 
98
        #
 
99
        PIDFILE="$WORKING_DIR/$SERVERNAME.pid"
 
100
        start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name duende
 
101
        return 0
138
102
}
139
103
 
140
104
if [ -z "$SERVERS" ]
155
119
        for rcfile in $SERVERS
156
120
        do
157
121
            SERVERNAME=`echo $rcfile | sed 's/\//_/g;s/^_*//;' | awk -F. '{print $NF}'`
158
 
            do_start_logger
159
 
            case "$?" in
160
 
                0|1) [ "$VERBOSE" != no ] && log_progress_msg "$SERVERNAME-log" ;;
161
 
                2) [ "$VERBOSE" != no ] && log_end_msg 1
162
 
                exit 1
163
 
                ;;
164
 
            esac
165
 
            do_start_daemon
 
122
            do_start
166
123
            case "$?" in
167
124
                0|1) [ "$VERBOSE" != no ] && log_progress_msg "$SERVERNAME" ;;
168
125
                2) [ "$VERBOSE" != no ] && log_end_msg 1
177
134
        for rcfile in $SERVERS
178
135
        do
179
136
            SERVERNAME=`echo $rcfile | sed 's/\//_/g;s/^_*//;' | awk -F. '{print $NF}'`
180
 
            do_stop_daemon
 
137
            do_stop
181
138
            case "$?" in
182
139
                0|1) [ "$VERBOSE" != no ] && log_progress_msg "$SERVERNAME" ;;
183
140
                2) [ "$VERBOSE" != no ] && log_end_msg 1
184
141
                exit 1
185
142
                ;;
186
143
            esac
187
 
            do_stop_logger
188
 
            case "$?" in
189
 
                0|1) [ "$VERBOSE" != no ] && log_progress_msg "$SERVERNAME-log" ;;
190
 
                2) [ "$VERBOSE" != no ] && log_end_msg 1
191
 
                exit 1
192
 
                ;;
193
 
            esac
194
144
        done
195
145
        [ "$VERBOSE" != no ] && log_end_msg 0
196
146
        ;;
198
148
        for rcfile in $SERVERS
199
149
        do
200
150
            SERVERNAME=`echo $rcfile | sed 's/\//_/g;s/^_*//;' | awk -F. '{print $NF}'`
201
 
            status_of_proc -p "$WORKING_DIR/$SERVERNAME-log.pid" /usr/bin/logger $SERVERNAME || exit $?
202
 
            status_of_proc -p "$WORKING_DIR/$SERVERNAME.pid" /usr/sbin/maradns "$SERVERNAME-log" || exit $?
 
151
            status_of_proc -p "$WORKING_DIR/$SERVERNAME.pid" $DAEMON $SERVERNAME || exit $?
203
152
        done
204
153
        exit 0
205
154
        ;;
206
 
  #reload|force-reload)
207
 
        #
208
 
        # This is not a viable option just now. See #484466.
209
 
        # Refresh from /etc/init.d/skeleton if it ever does become possible.
210
 
        #
211
 
        #;;
212
 
  restart|force-reload)
213
 
        #
214
 
        # If the "reload" option is implemented then remove the
215
 
        # 'force-reload' alias
216
 
        #
 
155
  reload|force-reload)
 
156
        for rcfile in $SERVERS
 
157
        do
 
158
            SERVERNAME=`echo $rcfile | sed 's/\//_/g;s/^_*//;' | awk -F. '{print $NF}'`
 
159
            log_daemon_msg "Reloading $DESC" "$NAME"
 
160
            do_reload
 
161
            case "$?" in
 
162
                0|1) [ "$VERBOSE" != no ] && log_progress_msg "$SERVERNAME" ;;
 
163
                2) [ "$VERBOSE" != no ] && log_end_msg 1
 
164
                exit 1
 
165
                ;;
 
166
            esac
 
167
        done
 
168
        log_end_msg 0
 
169
        ;;
 
170
  restart)
217
171
        $0 stop
218
172
        [ "$?" = "0" ] || exit "$?"
219
173
        sleep 3
220
174
        $0 start
221
175
        ;;       
222
176
  *)
223
 
        #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
224
 
        echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
 
177
        echo "Usage: $SCRIPTNAME {start|stop|status|restart|reload|force-reload}" >&2
225
178
        exit 3
226
179
        ;;
227
180
esac