File: client.init

package info (click to toggle)
puppet-agent 8.10.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 27,392 kB
  • sloc: ruby: 286,820; sh: 492; xml: 116; makefile: 88; cs: 68
file content (169 lines) | stat: -rw-r--r-- 3,630 bytes parent folder | download | duplicates (4)
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/bash
# puppet        Init script for running the puppet client daemon
#
# Author:       Duane Griffin <d.griffin@psenterprise.com>
#               David Lutterkort <dlutter@redhat.com>
#
# chkconfig: - 98 02
#
# description: Enables periodic system configuration checks through puppet.
# processname: puppet
# config: /etc/sysconfig/puppet

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

[ -f /etc/sysconfig/puppet ] && . /etc/sysconfig/puppet
lockfile=/var/lock/subsys/puppet
piddir=/var/run/puppetlabs
pidfile="${piddir}/agent.pid"
puppetd=/opt/puppetlabs/puppet/bin/puppet
pid=$(cat "$pidfile" 2> /dev/null)
RETVAL=0

PUPPET_OPTS="agent "

# 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"
    USEINITFUNCTIONS=true
fi

# Figure out if the system just booted. Let's assume
# boot doesn't take longer than 5 minutes
## Not used for now
##[ -n "$INIT_VERSION" ] && PUPPET_OPTS="${PUPPET_OPTS} --fullrun"

start() {
    echo -n $"Starting puppet agent: "
    mkdir -p $piddir
    daemon $daemonopts $puppetd ${PUPPET_OPTS} ${PUPPET_EXTRA_OPTS}
    RETVAL=$?
    echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}

stop() {
    echo -n $"Stopping puppet agent: "
    if [ "$USEINITFUNCTIONS" = "true" ]; then
      killproc $pidopts $puppetd
      RETVAL=$?
    else
      if [ -n "${pid}" ]; then
        kill -TERM $pid >/dev/null 2>&1
        RETVAL=$?
      fi
    fi
    echo
    [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
    return $RETVAL
}

reload() {
    echo -n $"Reloading puppet agent: "
    if [ "$USEINITFUNCTIONS" = "true" ]; then
      killproc $pidopts $puppetd -HUP
      RETVAL=$?
    else
      if [ -n "${pid}" ]; then
        kill -HUP $pid >/dev/null 2>&1
        RETVAL=$?
      else
        RETVAL=0
      fi
    fi
    echo
    return $RETVAL
}

rotate() {
    echo -n $"Reopening log files for puppet agent: "
    killproc $pidopts $puppetd -USR2
    RETVAL=$?
    echo
    return $RETVAL
}

restart() {
    stop
    start
}

rh_status() {
    base=puppet
    if [ "$USEINITFUNCTIONS" = "true" ]; then
      status $pidopts $puppetd
      RETVAL=$?
      return $RETVAL
    else
      if [ -n "${pid}" ]; then
        if `ps -p $pid | grep $pid > /dev/null 2>&1`; then
          echo "${base} (pid ${pid}) is running..."
          RETVAL=0
          return $RETVAL
        fi
      fi
      if [ -f "${pidfile}" ] ; then
        echo "${base} dead but pid file exists"
        RETVAL=1
        return $RETVAL
      fi
      if [ -f "${lockfile}" ]; then
        echo "${base} dead but subsys locked"
        RETVAL=2
        return $RETVAL
      fi
      echo "${base} is stopped"
      RETVAL=3
      return $RETVAL
    fi
}

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

genconfig() {
    echo -n $"Generate puppet agent configuration: "
    $puppetd ${PUPPET_OPTS} ${PUPPET_EXTRA_OPTS} --genconfig
}

case "$1" in
    start)
        start
    ;;
    stop)
        stop
    ;;
    restart)
        restart
    ;;
    rotate)
        rotate
    ;;
    reload|force-reload)
        reload
    ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        restart
    ;;
    status)
        rh_status
    ;;
    once)
        shift
        $puppetd ${PUPPET_OPTS} --onetime ${PUPPET_EXTRA_OPTS} $@
        ;;
    genconfig)
        genconfig
    ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart|rotate|once|genconfig}"
        exit 1
esac

exit $RETVAL