1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
#! /bin/sh
#
### BEGIN INIT INFO
# Provides: cfengine2
# Required-Start: $remote_fs $network $time $syslog
# Required-Stop: $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: GNU configuration engine
# Description: Tool for configuring and maintaining network machines
### END INIT INFO
#
# chkconfig: 2345 60 40
# description: Starts the cfengine daemons for remote and periodic \
# execution of cfengine and for environment monitoring.
#
set -e
CFEXECD=/usr/sbin/cfexecd
CFSERVD=/usr/sbin/cfservd
CFENVD=/usr/sbin/cfenvd
PATH=/sbin:/bin:/usr/sbin:/usr/bin
# Has the package been 'removed' but not purged?
test -f $CFEXECD || exit 0
. /lib/lsb/init-functions
# Source the config file
DEFAULT=/etc/default/cfengine2
if [ -f $DEFAULT ]; then
. $DEFAULT
else
RUN_CFSERVD=1
RUN_CFEXECD=1
RUN_CFENVD=1
fi
# Return-status
RETVAL=0
if /sbin/start-stop-daemon -V >/dev/null 2>&1; then
# start-stop-daemon runs OK
SSD=1
else
# Probably not a Debian system
SSD=0
fi
ctrl_daemon () {
# Usage: ctrl_daemon <op> <daemon> <timeout> [<args>]
# where <op> is 'start' or 'stop'. 'stop' args are passed to
# start-stop-daemon.
OPERATION=$1; shift
DAEMON=$1; shift
DAEMONNAME=$(basename $DAEMON)
case $OPERATION in
"start")
set +e
if [ "$SSD" = "1" ]; then
CMD="start-stop-daemon --start --quiet --exec $DAEMON -- $@"
else
CMD="$DAEMON $@"
fi
log_progress_msg "$DAEMONNAME "
$CMD || RETVAL=1
set -e
;;
"stop")
set +e
log_progress_msg "$DAEMONNAME "
DAEMON=`basename $DAEMON`
if [ "$SSD" = "1" ]; then
start-stop-daemon -o --stop --retry 5 --quiet --name "$DAEMON" "$@"
else
pkill `basename $DAEMON` 2>/dev/null
fi
[ $? = 0 ] || RETVAL=1
set -e
;;
"status")
set +e
log_progress_msg "$DAEMONNAME "
DAEMON=`basename $DAEMON`
status_of_proc "$DAEMONNAME" "$DAEMON"
[ $? = 0 ] || RETVAL=1
;;
"*")
log_warning_msg "cfengine2: Invalid operation, must be 'start' or 'stop'."
;;
esac
}
case "$1" in
start)
RETVAL=0
case "$RUN_CFENVD $RUN_CFEXECD $RUN_CFSERVD" in
*1*) ;;
*) log_action_msg "Cfengine2 is disabled in $DEFAULT"
exit 0;;
esac
log_daemon_msg "Starting cfengine2"
if [ "$RUN_CFENVD" = "1" ]; then
ctrl_daemon start "$CFENVD"
fi
if [ "$RUN_CFEXECD" = "1" ]; then
ctrl_daemon start "$CFEXECD"
fi
if [ "$RUN_CFSERVD" = "1" ]; then
if [ -f /etc/cfengine/cfservd.conf ]; then
ctrl_daemon start "$CFSERVD" "$CFSERVD_ARGS"
else
log_warning_msg "Not starting cfservd (/etc/cfengine/cfservd.conf missing)"
fi
fi
log_end_msg $RETVAL
;;
stop)
RETVAL=0
log_daemon_msg "Stopping cfengine2"
if [ "$RUN_CFENVD" = "1" ]; then
ctrl_daemon stop "$CFENVD"
fi
if [ "$RUN_CFEXECD" = "1" ]; then
ctrl_daemon stop "$CFEXECD"
fi
if [ "$RUN_CFSERVD" = "1" ]; then
ctrl_daemon stop "$CFSERVD"
fi
log_end_msg $RETVAL
;;
status)
RETVAL=0
log_daemon_msg "Stopping cfengine2"
if [ "$RUN_CFENVD" = "1" ]; then
ctrl_daemon status "$CFENVD"
fi
if [ "$RUN_CFEXECD" = "1" ]; then
ctrl_daemon status "$CFEXECD"
fi
if [ "$RUN_CFSERVD" = "1" ]; then
ctrl_daemon status "$CFSERVD"
fi
log_end_msg $RETVAL
;;
reload)
;;
restart|force-reload)
$0 stop
sleep 1
$0 start
;;
*)
N=/etc/init.d/cfengine2
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
|