summaryrefslogtreecommitdiffstats
path: root/conf/redhat/server.init
blob: 4d3a72c0ee29a4b687119f083876444d77a5c399 (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash
# puppetmaster  This shell script enables the puppetmaster server.
#
# Authors:       Duane Griffin <d.griffin@psenterprise.com>
#                Peter Meier <peter.meier@immerda.ch> (Mongrel enhancements)
#
# 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
pidfile=/var/run/puppet/master.pid

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

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

PUPPETMASTER_OPTS=""
[ -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}"

# Determine if we can use the -p option to daemon, killproc, and status.
# RHEL < 5 can't.
if status | grep -q -- '-p' 2>/dev/null; then
    daemonopts="--pidfile $pidfile"
    pidopts="-p $pidfile"
fi

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
            for ((i=0; i<${#PUPPETMASTER_PORTS[@]}; i++)); do
                echo -en "\nPort: ${PUPPETMASTER_PORTS[$i]}"
                daemon $PUPPETMASTER $PUPPETMASTER_OPTS --masterport=${PUPPETMASTER_PORTS[$i]} --pidfile=/var/run/puppet/puppetmaster.${PUPPETMASTER_PORTS[$i]}.pid
                ret=$?; [ $ret != 0 ] && RETVAL=$ret
            done
        else
            daemon $daemonopts $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
        for ((i=0; i<${#PUPPETMASTER_PORTS[@]}; i++)); do
            echo -en "\nPort: ${PUPPETMASTER_PORTS[$i]}"
            killproc -p /var/run/puppet/puppetmaster.${PUPPETMASTER_PORTS[$i]}.pid puppetmaster
            ret=$?; [ $ret != 0 ] && RETVAL=$ret
        done
    else
        killproc $pidopts $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
}

rh_status() {
    if [ -n "$PUPPETMASTER_PORTS" ] && [ ${#PUPPETMASTER_PORTS[@]} -gt 1 ]; then
        for ((i=0; i<${#PUPPETMASTER_PORTS[@]}; i++)); do
            echo -en "Port ${PUPPETMASTER_PORTS[$i]}: "
            status -p /var/run/puppet/puppetmaster.${PUPPETMASTER_PORTS[$i]}.pid puppetmaster
            ret=$?; [ $ret != 0 ] && RETVAL=$ret
        done
    else
        status $pidopts $PUPPETMASTER
        RETVAL=$?
    fi
    return $RETVAL
}

rh_status_q() {
        rh_status >/dev/null 2>&1
}

case "$1" in
  start)
      start
    ;;
    stop)
        stop
    ;;
    restart|reload|force-reload)
        restart
    ;;
    condrestart)
        rh_status_q || exit 0
        restart
    ;;
    status)
        rh_status
    ;;
    genconfig)
        genconfig
    ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart|genconfig}"
        exit 1
esac

exit $RETVAL