/mandos/release

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/release
162 by Teddy Hogeborn
* Makefile (PIDDIR, USER, GROUP): New variables.
1
#! /bin/sh
2
### BEGIN INIT INFO
3
# Provides:          mandos
237.2.130 by Teddy Hogeborn
* init.d-mandos: Bug fix: Correct the LSB header.
4
# Required-Start:    $remote_fs avahi
5
# Required-Stop:     $remote_fs avahi
162 by Teddy Hogeborn
* Makefile (PIDDIR, USER, GROUP): New variables.
6
# Default-Start:     2 3 4 5
7
# Default-Stop:      0 1 6
8
# Short-Description: Mandos server
9
# Description:       Gives encrypted passwords to Mandos clients
10
### END INIT INFO
11
12
# Author: Teddy Hogeborn <teddy@fukt.bsnet.se>
13
# Author: Björn Påhlsson <belorn@fukt.bsnet.se>
14
#
15
# Please remove the "Author" lines above and replace them
16
# with your own name if you copy and modify this script.
17
18
# Do NOT "set -e"
19
20
# PATH should only include /usr/* if it runs after the mountnfs.sh script
21
PATH=/sbin:/usr/sbin:/bin:/usr/bin
163 by Teddy Hogeborn
* Makefile (PIDDIR, USER, GROUP): Removed.
22
DESC="Mandos root file system password server"
162 by Teddy Hogeborn
* Makefile (PIDDIR, USER, GROUP): New variables.
23
NAME=mandos
24
DAEMON=/usr/sbin/$NAME
25
DAEMON_ARGS=""
163 by Teddy Hogeborn
* Makefile (PIDDIR, USER, GROUP): Removed.
26
PIDFILE=/var/run/$NAME.pid
162 by Teddy Hogeborn
* Makefile (PIDDIR, USER, GROUP): New variables.
27
SCRIPTNAME=/etc/init.d/$NAME
28
29
# Exit if the package is not installed
30
[ -x "$DAEMON" ] || exit 0
31
32
# Read configuration variable file if it is present
33
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
34
35
if [ -n "$CONFIGDIR" ]; then
36
   DAEMON_ARGS="$DAEMON_ARGS --configdir $CONFIGDIR"
37
fi
38
39
# Load the VERBOSE setting and other rcS variables
40
. /lib/init/vars.sh
41
42
# Define LSB log_* functions.
43
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
44
. /lib/lsb/init-functions
45
46
#
47
# Function that starts the daemon/service
48
#
49
do_start()
50
{
51
	# Return
52
	#   0 if daemon has been started
53
	#   1 if daemon was already running
54
	#   2 if daemon could not be started
55
	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
56
		|| return 1
57
	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
58
		$DAEMON_ARGS \
59
		|| return 2
60
	# Add code here, if necessary, that waits for the process to be ready
61
	# to handle requests from services started subsequently which depend
62
	# on this one.  As a last resort, sleep for some time.
63
}
64
65
#
66
# Function that stops the daemon/service
67
#
68
do_stop()
69
{
70
	# Return
71
	#   0 if daemon has been stopped
72
	#   1 if daemon was already stopped
73
	#   2 if daemon could not be stopped
74
	#   other if a failure occurred
75
	start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
76
	RETVAL="$?"
77
	[ "$RETVAL" = 2 ] && return 2
78
	# Wait for children to finish too if this is a daemon that forks
79
	# and if the daemon is only ever run from this initscript.
80
	# If the above conditions are not satisfied then add some other code
81
	# that waits for the process to drop all resources that could be
82
	# needed by services started subsequently.  A last resort is to
83
	# sleep for some time.
84
	start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
85
	[ "$?" = 2 ] && return 2
86
	# Many daemons don't delete their pidfiles when they exit.
87
	rm -f $PIDFILE
88
	return "$RETVAL"
89
}
90
91
#
92
# Function that sends a SIGHUP to the daemon/service
93
#
94
do_reload() {
95
	#
96
	# If the daemon can reload its configuration without
97
	# restarting (for example, when it is sent a SIGHUP),
98
	# then implement that here.
99
	#
100
	start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
101
	return 0
102
}
103
104
case "$1" in
105
  start)
106
	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
107
	do_start
108
	case "$?" in
109
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
110
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
111
	esac
112
	;;
113
  stop)
114
	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
115
	do_stop
116
	case "$?" in
117
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
118
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
119
	esac
120
	;;
121
  #reload|force-reload)
122
	#
123
	# If do_reload() is not implemented then leave this commented out
124
	# and leave 'force-reload' as an alias for 'restart'.
125
	#
126
	#log_daemon_msg "Reloading $DESC" "$NAME"
127
	#do_reload
128
	#log_end_msg $?
129
	#;;
130
  restart|force-reload)
131
	#
132
	# If the "reload" option is implemented then remove the
133
	# 'force-reload' alias
134
	#
135
	log_daemon_msg "Restarting $DESC" "$NAME"
136
	do_stop
137
	case "$?" in
138
	  0|1)
139
		do_start
140
		case "$?" in
141
			0) log_end_msg 0 ;;
142
			1) log_end_msg 1 ;; # Old process is still running
143
			*) log_end_msg 1 ;; # Failed to start
144
		esac
145
		;;
146
	  *)
147
	  	# Failed to stop
148
		log_end_msg 1
149
		;;
150
	esac
151
	;;
152
  *)
153
	#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
154
	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
155
	exit 3
156
	;;
157
esac
158
159
: