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 170
|
#!/bin/bash
# SPDX-License-Identifier: LGPL-2.1-only
#
# Start/Stop the CGroups Rules Engine Daemon
#
# Copyright Red Hat Inc. 2008
#
# Authors: Steve Olivieri <sjo@redhat.com>
#
# cgred CGroups Rules Engine Daemon
# chkconfig: - 14 86
# description: This is a daemon for automatically classifying processes \
# into cgroups based on UID/GID.
#
# processname: cgrulesengd
# pidfile: /var/run/cgred.pid
#
### BEGIN INIT INFO
# Provides: cgrulesengd
# Required-Start: $local_fs $syslog $cgconfig
# Required-Stop: $local_fs $syslog
# Should-Start:
# Should-Stop:
# Short-Description: start and stop the cgroups rules engine daemon
# Description: CGroup Rules Engine is a tool for automatically using \
# cgroups to classify processes
### END INIT INFO
sbindir=@sbindir@
CGRED_BIN=$sbindir/cgrulesengd
# Sanity checks
[[ -x $CGRED_BIN ]] || exit 0
#
# Source LSB routines
#
SYSLIBFILE=/lib/lsb/init-functions
OLDSYSLIBFILE=/etc/init.d/functions
if [[ -x $SYSLIBFILE ]] ; then
# shellcheck disable=SC1090
source $SYSLIBFILE
elif [[ -x $OLDSYSLIBFILE ]] ; then
# shellcheck disable=SC1090
source $OLDSYSLIBFILE
log_warning_msg() ( warning "$@" ; printf "\n" 1>&2 ; )
log_failure_msg() ( failure "$@" ; printf "\n" 1>&2 ; )
log_success_msg() ( success "$@" ; printf "\n" 1>&2 ; )
else
log_warning_msg() ( printf "warning:%s\n" "$@" 1>&2 ;)
log_failure_msg() ( printf "failure:%s\n" "$@" 1>&2 ;)
log_success_msg() ( printf "success:%s\n" "$@" 1>&2 ;)
fi
# Read in configuration options.
if [[ -f "/etc/sysconfig/cgred.conf" ]] ; then
# shellcheck disable=SC1091
source /etc/sysconfig/cgred.conf
OPTIONS="$NODAEMON $LOG"
if [[ -n "$LOG_FILE" ]]; then
OPTIONS="$OPTIONS --logfile=$LOG_FILE"
fi
if [[ -n "$SOCKET_USER" ]]; then
OPTIONS="$OPTIONS -u $SOCKET_USER"
fi
if [[ -n "$SOCKET_GROUP" ]]; then
OPTIONS="$OPTIONS -g $SOCKET_GROUP"
fi
else
OPTIONS=""
fi
# For convenience
processname=cgrulesengd
servicename=cgred
lockfile="/var/lock/subsys/$servicename"
pidfile=/var/run/cgred.pid
start()
{
echo -n $"Starting CGroup Rules Engine Daemon: "
if [[ -f "$lockfile" ]]; then
log_failure_msg "$servicename is already running with PID $(cat ${pidfile})"
return 0
fi
num=$(grep "cgroup" /proc/mounts | awk '$3=="cgroup"' | wc -l)
if [[ "$num" -eq 0 ]]; then
echo
log_failure_msg $"Cannot find cgroups, is cgconfig service running?"
return 1
fi
daemon --check $servicename --pidfile $pidfile $CGRED_BIN $OPTIONS
retval=$?
echo
if [[ $retval -ne 0 ]]; then
return 7
fi
if ! touch "$lockfile"; then
return 1
fi
pidof "$processname" > $pidfile
return 0
}
stop()
{
echo -n $"Stopping CGroup Rules Engine Daemon..."
if [[ ! -f $pidfile ]]; then
log_success_msg
return 0
fi
killproc -p $pidfile -TERM "$processname"
retval=$?
echo
if [[ $retval -ne 0 ]]; then
return 1
fi
rm -f "$lockfile" "$pidfile"
return 0
}
RETVAL=0
# See how we are called
case "$1" in
start)
start
RETVAL=$?
;;
stop)
stop
RETVAL=$?
;;
status)
status -p $pidfile $servicename
RETVAL=$?
;;
restart)
stop
start
RETVAL=$?
;;
condrestart)
if [[ -f "$lockfile" ]]; then
stop
start
RETVAL=$?
fi
;;
reload|flash)
if [[ -f "$lockfile" ]]; then
echo $"Reloading rules configuration..."
kill -s 12 "$(cat ${pidfile})"
RETVAL=$?
if [[ $RETVAL -eq 0 ]] ; then
log_success_msg ""
else
log_failure_msg ""
fi
else
log_failure_msg "$servicename is not running."
fi
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
RETVAL=2
;;
esac
exit $RETVAL
|