3 # Copyright (c) 2013-2015 Red Hat.
4 # Copyright (c) 2005 Silicon Graphics, Inc. All Rights Reserved.
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the
8 # Free Software Foundation; either version 2 of the License, or (at your
9 # option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 # Start or Stop the Performance Co-Pilot (PCP) daemon manager
18 # The following is for chkconfig on RedHat based systems
19 # chkconfig: 2345 95 05
20 # description: pmmgr is a daemon manager for the Performance Co-Pilot (PCP)
22 # The following is for insserv(1) based systems,
23 # e.g. SuSE, where chkconfig is a perl script.
26 # Required-Start: $remote_fs
27 # Should-Start: $local_fs $network $syslog $time $pmcd
28 # Required-Stop: $remote_fs
29 # Should-Stop: $local_fs $network $syslog $pmcd
30 # Default-Start: 2 3 4 5
32 # Short-Description: Control pmmgr (daemon manager for PCP)
33 # Description: Configure and control pmmgr (a daemon manager for the Performance Co-Pilot)
36 .
$PCP_DIR/etc
/pcp.env
37 .
$PCP_SHARE_DIR/lib
/rc-proc.sh
39 PMMGR
=$PCP_BINADM_DIR/pmmgr
40 PMMGROPTS
=$PCP_PMMGROPTIONS_PATH
41 RUNDIR
=$PCP_LOG_DIR/pmmgr
42 pmprog
=$PCP_RC_DIR/pmmgr
43 prog
=$PCP_RC_DIR/`basename $0`
45 tmp
=`mktemp -d /var/tmp/pcp.XXXXXXXXX` ||
exit 1
47 trap "rm -rf $tmp; exit \$status" 0 1 2 3 15
49 if [ $pmprog = $prog ]
59 # nothing we can usefully do here, skip the test
64 # standard Unix/Linux style test
67 test -f /usr
/xpg
4/bin
/id
&& ID
=/usr
/xpg
4/bin
/id
69 IAM
=`$ID -u 2>/dev/null`
74 IAM
=`$ID | sed -e 's/.*uid=//' -e 's/(.*//'`
83 _get_pids_by_name pmmgr
>$tmp/tmp
86 [ "$1" = verbose
] && echo "$pmprog: pmmgr not running"
90 # Send pmmgr a SIGTERM, which is noted as a pending shutdown.
91 # When finished the currently active request, pmmgr will close any
92 # connections and then exit.
93 # Wait for pmmgr to terminate.
95 pmsignal
-p -s TERM pmmgr
> /dev
/null
2>&1
96 $ECHO $PCP_ECHO_N "Waiting for pmmgr to terminate ...""$PCP_ECHO_C"
101 _get_pids_by_name pmmgr
>$tmp/tmp
108 # If pmmgr doesn't go in 15 seconds, SIGKILL and sleep 1 more time
109 # to allow any clients reading from pmmgr sockets to fail so that
110 # socket doesn't end up in TIME_WAIT or somesuch.
116 $PCP_PS_PROG $PCP_PS_ALL_FLAGS >$tmp/ps
118 for pid
in `cat $tmp/tmp`
120 $PCP_AWK_PROG <$tmp/ps
"\$2 == $pid { print }"
122 echo "$prog: Warning: Forcing pmmgr to terminate!"
123 pmsignal
-a -s KILL pmmgr
> /dev
/null
2>&1
125 $ECHO $PCP_ECHO_N ".""$PCP_ECHO_C"
128 if [ $gone != 1 ] # It just WON'T DIE, give up.
132 echo "$prog: Warning: pmmgr won't die!"
136 pmpost
"stop pmmgr from $pmprog"
141 echo "Usage: $pmprog [-v] {start|restart|condrestart|stop|status|reload|force-reload}"
158 shift `expr $OPTIND - 1`
160 if [ $VERBOSE_CTL = on
]
161 then # For a verbose startup and shutdown
163 else # For a quiet startup and shutdown
167 if [ "$IAM" != 0 -a "$1" != "status" ]
171 : running
in a non-default installation
, do not need to be root
174 Error: You must be root (uid 0) to start or stop the PCP pmmgr daemon.'
179 # First reset status of this service
182 # Return values acc. to LSB for all commands but status:
185 # 2 - invalid or excess args
186 # 3 - unimplemented feature (e.g. reload)
187 # 4 - insufficient privilege
188 # 5 - program not installed
189 # 6 - program not configured
191 # Note that starting an already running service, stopping
192 # or restarting a not-running service as well as the restart
193 # with force-reload (in case signalling is not supported) are
194 # considered a success.
197 'start'|
'restart'|
'condrestart'|
'reload'|
'force-reload')
198 if [ "$1" = "condrestart" ] && ! is_chkconfig_on pmmgr
206 # pmmgr messages should go to stderr, not the GUI notifiers
212 if [ ! -f $PMMGROPTS ]
215 Error: pmmgr control file "$PMMGROPTS" is missing, cannot start pmmgr.'
218 # create directory housing daemon pid file
219 if [ ! -d "$PCP_RUN_DIR" ]
221 mkdir
-p -m 775 "$PCP_RUN_DIR"
222 chown
$PCP_USER:$PCP_GROUP "$PCP_RUN_DIR"
224 # create directory which will serve as cwd
225 if [ ! -d "$RUNDIR" ]
227 mkdir
-p -m 775 "$RUNDIR"
228 chown
$PCP_USER:$PCP_GROUP "$RUNDIR"
232 # salvage the previous versions of any pmmgr
237 mv pmmgr.log pmmgr.log.prev
240 $ECHO $PCP_ECHO_N "Starting pmmgr ..." "$PCP_ECHO_C"
241 # options file processing ...
242 # only consider lines which start with a hyphen
243 # get rid of the -f option
244 # ensure multiple lines concat onto 1 line
245 OPTS
=`sed <$PMMGROPTS 2>/dev/null \
256 eval `sed -e 's/"/\\"/g' $PMMGROPTS \
259 /^[A-Z]/ && NF == 2 { exports=exports" "$1
260 printf "%s=${%s:-\"%s\"}\n", $1, $1, $2
262 END { if (exports != "") print "export", exports }'`
264 $PMMGR -l pmmgr.log
$OPTS &
267 pmpost
"start pmmgr from $pmprog"
269 # finally, stop here if running in a container
270 [ -z "$PCP_CONTAINER_IMAGE" ] ||
exec $PCP_BINADM_DIR/pmpause
281 # NOTE: $RC_CHECKPROC returns LSB compliant status values.
282 $ECHO $PCP_ECHO_N "Checking for pmmgr:" "$PCP_ECHO_C"
283 if [ -r /etc
/rc.status
]
303 [ -z "$PCP_CONTAINER_IMAGE" ] ||
exec "$@"