Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initscripts: use debian 6.0 skeleton
recreate Debian and Ubuntu init scripts based on Debian/Ubuntu skeleton file. Advantages: - use standard skeleton - "status" is now implemented and working, see bug #50 - start order: if a database is installed, it is started before the bareos-director - Debian and Ubuntu are using the same init scripts - bareos-dir, bareos-sd and bareos-fd are based on the same skeleton and differ only at the variables values Changed: - Debian standard skeleton utilise the VERBOSE variable. By default, VERBOSE equals "no" and init script are completly quiet. We follow this standard, even so we don't like it. This behavior can be changed by setting "VERBOSE=yes" in /etc/defaults/rcS Signed-off-by: Marco van Wieringen <marco.van.wieringen@bareos.com>
- Loading branch information
1 parent
b765842
commit e82b5ed
Showing
7 changed files
with
482 additions
and
445 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,177 @@ | ||
#! /bin/sh | ||
# | ||
# bareos This shell script takes care of starting and stopping | ||
# the bareos Director daemon on Debian/Ubuntu/Kubuntu | ||
# systems. | ||
# | ||
# Kern E. Sibbald - 21 March 2008 | ||
# | ||
# For Bareos release @VERSION@ (@DATE@) -- @DISTNAME@ | ||
# | ||
### BEGIN INIT INFO | ||
# Provides: bareos-dir | ||
# Required-Start: $network | ||
# Required-Stop: $network | ||
# Provides: bareos-dir | ||
# Required-Start: $network $remote_fs $time $syslog | ||
# Should-Start: postgresql mysql bareos-sd bareos-fd | ||
# Required-Stop: $network $remote_fs $time $syslog | ||
# Should-Stop: postgresql mysq bareos-sd bareos-fd | ||
# Default-Start: 2 3 4 5 | ||
# Default-Stop: 0 1 6 | ||
# Short-Description: Start @BAREOS@ Director daemon at boot time | ||
# Description: Enable @BAREOS@ Director. | ||
# Short-Description: Bareos Director | ||
# Description: Bareos is a network backup and restore program. | ||
# The Bareos Director controls the Bareos Storage- and File-Daemons. | ||
### END INIT INFO | ||
# | ||
|
||
NAME="bareos-dir" | ||
DESC="@BAREOS@ Director" | ||
DAEMON=@sbindir@/${NAME} | ||
BUSER=@dir_user@ | ||
BGROUP=@dir_group@ | ||
BOPTIONS="-c @sysconfdir@/${NAME}.conf" | ||
BPORT=@dir_port@ | ||
|
||
PATH=/sbin:/bin:/usr/sbin:/usr/bin | ||
|
||
test -f $DAEMON || exit 0 | ||
DESC="Bareos Director" | ||
NAME=bareos-dir | ||
NETWORK_PORT=@dir_port@ | ||
DAEMON_USER=@dir_user@ | ||
DAEMON_GROUP=@dir_group@ | ||
|
||
if [ -n "`getent services ${NAME}`" ]; then | ||
BPORT=`getent services ${NAME} | awk '{ gsub("/tcp","",$2); print $2; }'` | ||
DAEMON=/usr/sbin/$NAME | ||
if [ "x${DAEMON_USER}" != "x" ]; then | ||
DAEMON_USERGROUP="--chuid ${DAEMON_USER}" | ||
if [ "x${DAEMON_GROUP}" != "x" ]; then | ||
DAEMON_USERGROUP="${DAEMON_USERGROUP}:${DAEMON_GROUP}" | ||
fi | ||
fi | ||
DAEMON_ARGS= | ||
PIDFILE=@piddir@/${NAME}.${NETWORK_PORT}.pid | ||
SCRIPTNAME=/etc/init.d/$NAME | ||
PATH=/sbin:/usr/sbin:/bin:/usr/bin | ||
|
||
if [ -f /etc/default/$NAME ]; then | ||
. /etc/default/$NAME | ||
fi | ||
# Exit if the package is not installed | ||
[ -x "$DAEMON" ] || exit 0 | ||
|
||
PIDFILE=@piddir@/${NAME}.${BPORT}.pid | ||
# Read configuration variable file if it is present | ||
[ -r /etc/default/$NAME ] && . /etc/default/$NAME | ||
|
||
if [ "x${BUSER}" != "x" ]; then | ||
USERGRP="--chuid ${BUSER}" | ||
if [ "x${BGROUP}" != "x" ]; then | ||
USERGRP="${USERGRP}:${BGROUP}" | ||
fi | ||
fi | ||
# Load the VERBOSE setting and other rcS variables | ||
. /lib/init/vars.sh | ||
|
||
# define LSB functions. | ||
# Define LSB log_* functions. | ||
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present | ||
# and status_of_proc is working. | ||
. /lib/lsb/init-functions | ||
|
||
# | ||
# Function that starts the daemon/service | ||
# | ||
do_start() | ||
{ | ||
# Return | ||
# 0 if daemon has been started | ||
# 1 if daemon was already running | ||
# 2 if daemon could not be started | ||
start-stop-daemon --start --quiet --pidfile $PIDFILE $DAEMON_USERGROUP --exec $DAEMON --test > /dev/null \ | ||
|| return 1 | ||
start-stop-daemon --start --quiet --pidfile $PIDFILE $DAEMON_USERGROUP --exec $DAEMON -- \ | ||
$DAEMON_ARGS \ | ||
|| return 2 | ||
# Add code here, if necessary, that waits for the process to be ready | ||
# to handle requests from services started subsequently which depend | ||
# on this one. As a last resort, sleep for some time. | ||
TIMEOUT=5 | ||
while [ $TIMEOUT -gt 0 ] && ! do_check; do | ||
sleep 1 | ||
TIMEOUT=$((TIMEOUT-1)) | ||
done | ||
do_check | ||
return $? | ||
} | ||
|
||
# | ||
# Function that stops the daemon/service | ||
# | ||
do_stop() | ||
{ | ||
# Return | ||
# 0 if daemon has been stopped | ||
# 1 if daemon was already stopped | ||
# 2 if daemon could not be stopped | ||
# other if a failure occurred | ||
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE $DAEMON_USERGROUP --name $NAME | ||
RETVAL="$?" | ||
[ "$RETVAL" = 2 ] && return 2 | ||
# Wait for children to finish too if this is a daemon that forks | ||
# and if the daemon is only ever run from this initscript. | ||
# If the above conditions are not satisfied then add some other code | ||
# that waits for the process to drop all resources that could be | ||
# needed by services started subsequently. A last resort is to | ||
# sleep for some time. | ||
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 $DAEMON_USERGROUP --exec $DAEMON | ||
[ "$?" = 2 ] && return 2 | ||
# Many daemons don't delete their pidfiles when they exit. | ||
rm -f $PIDFILE | ||
return "$RETVAL" | ||
} | ||
|
||
# | ||
# Function that checks if daemon is running | ||
# | ||
do_check() | ||
{ | ||
STATUS=2 | ||
pidofproc -p $PIDFILE $DAEMON >/dev/null && lsof -i "TCP:${NETWORK_PORT}" -s "TCP:LISTEN" >/dev/null && STATUS=0 | ||
return $STATUS | ||
} | ||
|
||
# | ||
# Function that sends a SIGHUP to the daemon/service | ||
# | ||
do_reload() { | ||
# | ||
# If the daemon can reload its configuration without | ||
# restarting (for example, when it is sent a SIGHUP), | ||
# then implement that here. | ||
# | ||
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME | ||
return 0 | ||
} | ||
|
||
|
||
|
||
case "$1" in | ||
start) | ||
log_daemon_msg "Starting $DESC" "$NAME" | ||
start-stop-daemon --start --quiet --pidfile ${PIDFILE} ${USERGRP} --exec ${DAEMON} -- ${BOPTIONS} | ||
log_end_msg $? | ||
sleep 2 | ||
start) | ||
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" | ||
do_start | ||
case "$?" in | ||
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; | ||
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; | ||
esac | ||
;; | ||
stop) | ||
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" | ||
do_stop | ||
case "$?" in | ||
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; | ||
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; | ||
esac | ||
;; | ||
status) | ||
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? | ||
;; | ||
reload|force-reload) | ||
# | ||
# If do_reload() is not implemented then leave this commented out | ||
# and leave 'force-reload' as an alias for 'restart'. | ||
# | ||
log_daemon_msg "Reloading $DESC" "$NAME" | ||
do_reload | ||
log_end_msg $? | ||
;; | ||
restart) | ||
log_daemon_msg "Restarting $DESC" "$NAME" | ||
do_stop | ||
case "$?" in | ||
0|1) | ||
do_start | ||
case "$?" in | ||
0) log_end_msg 0 ;; | ||
1) log_end_msg 1 ;; # Old process is still running | ||
*) log_end_msg 1 ;; # Failed to start | ||
esac | ||
;; | ||
stop) | ||
echo -n "Stopping ${DESC}: " | ||
start-stop-daemon --oknodo --stop --quiet ${USERGRP} --exec ${DAEMON} -- ${BOPTIONS} | ||
RETVAL=$? | ||
echo "${NAME}" | ||
;; | ||
restart|force-reload) | ||
$0 stop | ||
sleep 5 | ||
$0 start | ||
;; | ||
status) | ||
status_of_proc -p ${PIDFILE} ${DAEMON} ${NAME} && exit 0 || exit $? | ||
*) | ||
# Failed to stop | ||
log_end_msg 1 | ||
;; | ||
*) | ||
echo "Usage: /etc/init.d/${NAME} {start|stop|restart|force-reload}" >&2 | ||
exit 1 | ||
;; | ||
esac | ||
;; | ||
*) | ||
echo "Usage: $SCRIPTNAME {start|stop|status|restart|reload|force-reload}" >&2 | ||
exit 3 | ||
;; | ||
esac | ||
exit $RETVAL | ||
|
||
: |
Oops, something went wrong.