/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.7.192 by Teddy Hogeborn
Switch from avahi to avahi-daemon in initscript LSB dependencies
4
# Required-Start:    $remote_fs $syslog avahi-daemon
5
# Required-Stop:     $remote_fs $syslog avahi-daemon
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
237.7.186 by Teddy Hogeborn
Add systemd service support for Mandos server.
9
# Description:       Server of encrypted passwords to Mandos clients
162 by Teddy Hogeborn
* Makefile (PIDDIR, USER, GROUP): New variables.
10
### END INIT INFO
11
237.11.2 by Teddy Hogeborn
Change "fukt.bsnet.se" to "recompile.se" throughout.
12
# Author: Teddy Hogeborn <teddy@recompile.se>
13
# Author: Björn Påhlsson <belorn@recompile.se>
162 by Teddy Hogeborn
* Makefile (PIDDIR, USER, GROUP): New variables.
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=""
237.7.184 by Teddy Hogeborn
Fall back to /var/run for pidfile if /run is not a directory.
26
if [ -d /run/. ]; then
27
    PIDFILE=/run/$NAME.pid
28
else
29
    PIDFILE=/var/run/$NAME.pid
30
fi
162 by Teddy Hogeborn
* Makefile (PIDDIR, USER, GROUP): New variables.
31
SCRIPTNAME=/etc/init.d/$NAME
32
33
# Exit if the package is not installed
34
[ -x "$DAEMON" ] || exit 0
35
36
# Read configuration variable file if it is present
37
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
38
39
if [ -n "$CONFIGDIR" ]; then
40
   DAEMON_ARGS="$DAEMON_ARGS --configdir $CONFIGDIR"
41
fi
42
43
# Load the VERBOSE setting and other rcS variables
44
. /lib/init/vars.sh
45
46
# Define LSB log_* functions.
237.7.196 by Teddy Hogeborn
Update init script to modern standards.
47
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
48
# and status_of_proc is working.
162 by Teddy Hogeborn
* Makefile (PIDDIR, USER, GROUP): New variables.
49
. /lib/lsb/init-functions
50
51
#
52
# Function that starts the daemon/service
53
#
54
do_start()
55
{
56
	# Return
57
	#   0 if daemon has been started
58
	#   1 if daemon was already running
59
	#   2 if daemon could not be started
60
	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
61
		|| return 1
62
	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
63
		$DAEMON_ARGS \
64
		|| return 2
65
	# Add code here, if necessary, that waits for the process to be ready
66
	# to handle requests from services started subsequently which depend
67
	# on this one.  As a last resort, sleep for some time.
68
}
69
70
#
71
# Function that stops the daemon/service
72
#
73
do_stop()
74
{
75
	# Return
76
	#   0 if daemon has been stopped
77
	#   1 if daemon was already stopped
78
	#   2 if daemon could not be stopped
79
	#   other if a failure occurred
237.7.374 by Teddy Hogeborn
Server bug fix: Work around bug when stopping server
80
	start-stop-daemon --stop --quiet --pidfile $PIDFILE --name $NAME
81
	mandos-ctl >/dev/null 2>&1
82
	start-stop-daemon --stop --quiet --retry=30/KILL/5 --pidfile $PIDFILE --name $NAME
162 by Teddy Hogeborn
* Makefile (PIDDIR, USER, GROUP): New variables.
83
	RETVAL="$?"
84
	[ "$RETVAL" = 2 ] && return 2
85
	# Wait for children to finish too if this is a daemon that forks
86
	# and if the daemon is only ever run from this initscript.
87
	# If the above conditions are not satisfied then add some other code
88
	# that waits for the process to drop all resources that could be
89
	# needed by services started subsequently.  A last resort is to
90
	# sleep for some time.
91
	start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
92
	[ "$?" = 2 ] && return 2
93
	# Many daemons don't delete their pidfiles when they exit.
94
	rm -f $PIDFILE
95
	return "$RETVAL"
96
}
97
98
#
99
# Function that sends a SIGHUP to the daemon/service
100
#
101
do_reload() {
102
	#
103
	# If the daemon can reload its configuration without
104
	# restarting (for example, when it is sent a SIGHUP),
105
	# then implement that here.
106
	#
107
	start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
108
	return 0
109
}
110
111
case "$1" in
112
  start)
113
	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
114
	do_start
115
	case "$?" in
116
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
117
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
118
	esac
119
	;;
120
  stop)
121
	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
122
	do_stop
123
	case "$?" in
124
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
125
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
126
	esac
127
	;;
237.7.196 by Teddy Hogeborn
Update init script to modern standards.
128
  status)
129
	status_of_proc "$DAEMON" "$NAME" -p "$PIDFILE" && exit 0 || exit $?
130
	;;
162 by Teddy Hogeborn
* Makefile (PIDDIR, USER, GROUP): New variables.
131
  #reload|force-reload)
132
	#
133
	# If do_reload() is not implemented then leave this commented out
134
	# and leave 'force-reload' as an alias for 'restart'.
135
	#
136
	#log_daemon_msg "Reloading $DESC" "$NAME"
137
	#do_reload
138
	#log_end_msg $?
139
	#;;
140
  restart|force-reload)
141
	#
142
	# If the "reload" option is implemented then remove the
143
	# 'force-reload' alias
144
	#
145
	log_daemon_msg "Restarting $DESC" "$NAME"
146
	do_stop
147
	case "$?" in
148
	  0|1)
149
		do_start
150
		case "$?" in
151
			0) log_end_msg 0 ;;
152
			1) log_end_msg 1 ;; # Old process is still running
153
			*) log_end_msg 1 ;; # Failed to start
154
		esac
155
		;;
156
	  *)
237.7.196 by Teddy Hogeborn
Update init script to modern standards.
157
		# Failed to stop
162 by Teddy Hogeborn
* Makefile (PIDDIR, USER, GROUP): New variables.
158
		log_end_msg 1
159
		;;
160
	esac
161
	;;
162
  *)
163
	#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
237.7.196 by Teddy Hogeborn
Update init script to modern standards.
164
	echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
162 by Teddy Hogeborn
* Makefile (PIDDIR, USER, GROUP): New variables.
165
	exit 3
166
	;;
167
esac
168
169
: