summaryrefslogtreecommitdiff
path: root/files/cluster/init.d/puppetmaster.CentOS
blob: 5edf5a9c319281552c8c3f4b44a42b38d14fe1c6 (plain)
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/bash
# puppetmaster  This shell script enables the puppetmaster server.
#
# Author:       Duane Griffin <d.griffin@psenterprise.com>
#
# chkconfig: - 65 45
#
# description: Server for the puppet system management tool.
# processname: puppetmaster

PATH=/usr/bin:/sbin:/bin:/usr/sbin
export PATH

lockfile=/var/lock/subsys/puppetmaster

# Source function library.
. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/puppetmaster ]; then
	. /etc/sysconfig/puppetmaster
fi

PUPPETMASTER_OPTS=""
[ -n "$PUPPETMASTER_PID_DIR" ] || PUPPETMASTER_PID_DIR="/var/run/puppet/"
[ -n "$PUPPETMASTER_MANIFEST" ] && PUPPETMASTER_OPTS="--manifest=${PUPPETMASTER_MANIFEST}"
if [ -n "$PUPPETMASTER_PORTS" ] && [ ${#PUPPETMASTER_PORTS[@]} -gt 1 ]; then
    PUPPETMASTER_OPTS="$PUPPETMASTER_OPTS --servertype=mongrel"
elif [ -n "$PUPPETMASTER_PORTS" ] && [ ${#PUPPETMASTER_PORTS[@]} -eq 1 ]; then
    PUPPETMASTER_OPTS="${PUPPETMASTER_OPTS} --masterport=${PUPPETMASTER_PORTS[0]}" 
fi
[ -n "$PUPPETMASTER_LOG" ] && PUPPETMASTER_OPTS="${PUPPETMASTER_OPTS} --logdest=${PUPPETMASTER_LOG}"
PUPPETMASTER_OPTS="${PUPPETMASTER_OPTS} \
	${PUPPETMASTER_EXTRA_OPTS}"

RETVAL=0

prog=puppetmasterd
PUPPETMASTER=/usr/sbin/$prog

start() {
	echo -n $"Starting puppetmaster: "

	# Confirm the manifest exists
	if [ -r $PUPPETMASTER_MANIFEST ]; then
        if [ -n "$PUPPETMASTER_PORTS" ] && [ ${#PUPPETMASTER_PORTS[@]} -gt 1 ]; then
            echo -n " (port "
            for ((i=0; i<${#PUPPETMASTER_PORTS[@]}; i++)); do
                echo -n "${PUPPETMASTER_PORTS[$i]}"
                daemon $PUPPETMASTER $PUPPETMASTER_OPTS --masterport=${PUPPETMASTER_PORTS[$i]} --pidfile=$PUPPETMASTER_PID_DIR/puppetmaster.${PUPPETMASTER_PORTS[$i]}.pid
                RETVAL=$? || $RETVAL
            done
            echo -n ")"
        else
            daemon $PUPPETMASTER $PUPPETMASTER_OPTS
            RETVAL=$?
        fi
	else
		failure $"Manifest does not exist: $PUPPETMASTER_MANIFEST"
		echo
		return 1
	fi
	[ $RETVAL -eq 0 ] && touch "$lockfile"
	echo
	return $RETVAL
}

stop() {
	echo -n  $"Stopping puppetmaster: "
    if [ -n "$PUPPETMASTER_PORTS" ] && [ ${#PUPPETMASTER_PORTS[@]} -gt 1 ]; then
        echo -n " (port "
        for ((i=0; i<${#PUPPETMASTER_PORTS[@]}; i++)); do
            echo -n "${PUPPETMASTER_PORTS[$i]}"
            killproc -p $PUPPETMASTER_PID_DIR/puppetmaster.${PUPPETMASTER_PORTS[$i]}.pid $PUPPETMASTER
            RETVAL=$? || $RETVAL
        done
        echo -n ")"
    else
       killproc $PUPPETMASTER
       RETVAL=$?
    fi
	echo
	[ $RETVAL -eq 0 ] && rm -f "$lockfile"
	return $RETVAL
}

restart() {
  stop
  start
}

genconfig() {
  echo -n $"Generate configuration puppetmaster: "
  $PUPPETMASTER $PUPPETMASTER_OPTS --genconfig
}

case "$1" in
  start)
	start
	;;
  stop) 
	stop
	;;
  restart|reload|force-reload)
        restart
	;;
  condrestart)
	[ -f "$lockfile" ] && restart
	;;
  status)
	status $PUPPETMASTER
        RETVAL=$?
	;;
  genconfig)
	genconfig
	;;
  *)
	echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart|genconfig}"
	exit 1
esac

exit $RETVAL