File: cfengine2.init

package info (click to toggle)
cfengine2 2.1.14-1sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,688 kB
  • ctags: 12
  • sloc: sh: 290; makefile: 113; perl: 29
file content (121 lines) | stat: -rw-r--r-- 2,407 bytes parent folder | download
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
#! /bin/sh
#
# 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

# Source the config file
DEFAULT=/etc/default/cfengine2
if [ -f $DEFAULT ]; then
    . $DEFAULT
else
    RUN_CFSERVD=1
    RUN_CFEXECD=1
    RUN_CFENVD=1
fi
    

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
    case $OPERATION in
	"start")
	    printf '%s' " `basename $DAEMON`"
	    if [ "$SSD" = "1" ]; then
		CMD="start-stop-daemon --start --quiet --exec $DAEMON -- $@"
	    else
		CMD="$DAEMON $@"
	    fi
	    $CMD || printf '%s' '(failed)'
	    ;;
	"stop")
	    set +e
	    DAEMON=`basename $DAEMON`
	    if [ "$SSD" = "1" ]; then
		start-stop-daemon --stop --retry 5 --quiet --name "$DAEMON" "$@"
	    else
		pkill `basename $DAEMON` 2>/dev/null
	    fi
	    test $? = "0" && printf '%s' " `basename $DAEMON`"
	    set -e
	    ;;
	"*")
	    echo 'Invalid <op> to ctrl_daemon. Must be "start" or "stop".' >&2
	    ;;
    esac
}


case "$1" in
  start)
	case "$RUN_CFENVD $RUN_CFEXECD $RUN_CFSERVD" in
	    *1*) ;;
	    *) exit 0;;
	esac
	printf '%s' "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
		echo ""
		echo "Not starting cfservd: /etc/cfengine/cfservd.conf missing"
	    fi
	fi
	echo "."
	;;

  stop)
	printf '%s' "Stopping cfengine2:"
	for DAEMON in "$CFSERVD" "$CFEXECD" "$CFENVD"; do
	    ctrl_daemon stop "$DAEMON"
	done
	echo "."
	;;

  reload|force-reload)
	;;

  restart)
	echo "Restarting cfengine2:"
	$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