]> git.pld-linux.org Git - packages/libcgroup.git/commitdiff
- started work on PLD init scripts
authorJan Rękorajski <baggins@pld-linux.org>
Mon, 7 Feb 2011 23:34:32 +0000 (23:34 +0000)
committercvs2git <feedback@pld-linux.org>
Sun, 24 Jun 2012 12:13:13 +0000 (12:13 +0000)
Changed files:
    cgconfig.init -> 1.1
    cgred.init -> 1.1

cgconfig.init [new file with mode: 0644]
cgred.init [new file with mode: 0644]

diff --git a/cgconfig.init b/cgconfig.init
new file mode 100644 (file)
index 0000000..88f6861
--- /dev/null
@@ -0,0 +1,139 @@
+#!/bin/sh
+#
+# cgconfig     Control Groups Configuration Startup
+# chkconfig:   - 5 95
+# description: This script runs the cgconfigparser utility to parse and setup \
+#              the control group filesystem. It uses /etc/cgconfig.conf \
+#              and parses the configuration specified in there.
+
+# Source function library
+. /etc/rc.d/init.d/functions
+
+# read the config
+CREATE_DEFAULT=yes
+[ -f /etc/sysconfig/cgconfig ] && . /etc/sysconfig/cgconfig
+
+create_default_groups() {
+       local defaultcgroup
+
+        if [ -f /etc/cgrules.conf ]; then
+               defaultcgroup=$(awk '/^\*[\t ]+/ { print $3; exit }' /etc/cgrules.conf)
+               if [ -n "$defaultcgroup" -a "$defaultcgroup" = "*" ]; then
+                       log_warning_msg "/etc/cgrules.conf incorrect"
+                       log_warning_msg "Overriding it"
+                       defaultcgroup=
+               fi
+       fi
+
+       if [ -z $defaultcgroup ]; then
+               defaultcgroup=sysdefault/
+       fi
+
+        #
+        # Find all mounted subsystems and create comma-separated list
+        # of controllers.
+        #
+        controllers=`lssubsys 2>/dev/null | tr '\n' ',' | sed s/.$//`
+
+        #
+        # Create the default group, ignore errors when the default group
+        # already exists.
+        #
+        cgcreate -f 664 -d 775 -g $controllers:$defaultcgroup 2>/dev/null
+
+        #
+        # special rule for cpusets
+        #
+        if echo $controllers | grep -q -w cpuset; then
+                 cpus=`cgget -nv -r cpuset.cpus /`
+                 cgset -r cpuset.cpus=$cpus $defaultcgroup
+                 mems=`cgget -nv -r cpuset.mems /`
+                 cgset -r cpuset.mems=$mems $defaultcgroup
+        fi
+
+        #
+        # Classify everything to default cgroup. Ignore errors, some processes
+        # may exit after ps is run and before cgclassify moves them.
+        #
+        cgclassify -g $controllers:$defaultcgroup `ps --no-headers -eL o tid` 2>/dev/null || :
+}
+
+start() {
+       # Check if the service is already running?
+       if [ -f /var/lock/subsys/cgconfig ]; then
+               msg_already_running "cgconfig"
+               return
+       fi
+
+       msg_starting "cgconfig"
+       if [ ! -s /etc/cgconfig.conf ]; then
+               log_failure_msg "/etc/cgconfig.conf is not configured"
+               return 6
+       fi
+
+       /sbin/cgconfigparser -l /etc/cgconfig.conf
+       retval=$?
+       if [ $retval -ne 0 ]; then
+               log_failure_msg "Failed to parse /etc/cgconfig.conf"
+               return 1
+       fi
+
+       if [ $CREATE_DEFAULT = "yes" ]; then
+               create_default_groups
+       fi
+
+       touch /var/lock/subsys/cgconfig
+       retval=$?
+       if [ $retval -ne 0 ]; then
+               log_failure_msg "Failed to touch /var/lock/subsys/cgconfig"
+               return 1
+       fi
+       ok
+}
+
+stop() {
+       if [ -f /var/lock/subsys/cgconfig ]; then
+               msg_stopping "cgconfig"
+               cgclear
+               rm -f /var/lock/subsys/cgconfig
+               ok
+       else
+               msg_not_running "cgconfig"
+       fi
+}
+
+RETVAL=0
+
+case "$1" in
+  start)
+       start
+       ;;
+  stop)
+       stop;
+       ;;
+  restart|reload)
+       stop
+       start
+       ;;
+  condrestart)
+       if [ -f /var/lock/subsys/cgconfig ] ; then
+               stop
+               start
+       fi
+       ;;
+  status)
+       if [ -f /var/lock/subsys/cgconfig ] ; then
+               echo "Running"
+               exit 0
+       else
+               echo "Stopped"
+               exit 3
+       fi
+       ;;
+  *)
+       msg_usage "$0 {start|stop|restart|condrestart|status}"
+       exit 3
+       ;;
+esac
+
+exit $RETVAL
diff --git a/cgred.init b/cgred.init
new file mode 100644 (file)
index 0000000..fcbbdd2
--- /dev/null
@@ -0,0 +1,110 @@
+#!/bin/sh
+#
+# 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
+#
+
+# Source function library
+. /etc/rc.d/init.d/functions
+
+start() {
+       if [ -f "/var/lock/subsys/cgred" ] ; then
+               msg_already_running "CGroup Rules Engine Daemon"
+               return
+       fi
+
+       msg_staring "CGroup Rules Engine Daemon"
+       if [ ! -s /etc/cgrules.conf ]; then
+               log_failure_msg "not configured"
+               return 6
+       fi
+       if ! grep -qs "^cgroup" /proc/mounts ; then
+               log_failure_msg "Cannot find cgroups, is cgconfig service running?"
+               return 1
+       fi
+       # Read in configuration options.
+       OPTIONS=""
+       if [ -f "/etc/sysconfig/cgred.conf" ] ; then
+               . /etc/sysconfig/cgred.conf
+
+               OPTIONS="$NODAEMON $LOG"
+               [ -n "$LOG_FILE" ] && OPTIONS="$OPTIONS --logfile=$LOG_FILE"
+               [ -n "$SOCKET_USER" ] && OPTIONS="$OPTIONS -u $SOCKET_USER"
+               [ -n "$SOCKET_GROUP" ] && OPTIONS="$OPTIONS -g $SOCKET_GROUP"
+       fi
+
+       daemon --check cgred --pidfile /var/run/cgred.pid /sbin/cgrulesengd $OPTIONS
+       RETVAL=$?
+       if [ $RETVAL -ne 0 ]; then
+               return 7
+       fi
+       [ $RETVAL -eq 0 ] && touch /var/lock/subsys/cgred
+       echo "`pidof cgrulesengd`" > /var/run/cgred.pid
+}
+
+stop() {
+       if [ -f /var/lock/subsys/cgred ]; then
+               msg_stopping "CGroup Rules Engine Daemon"
+               killproc -p /var/run/cgred.pid cgrulesengd -TERM
+               RETVAL=$?
+               if [ $RETVAL -eq 0 ] ; then
+                       rm -f /var/lock/subsys/cgred
+                       rm -f /var/run/cgred.pid
+               fi
+       else
+               msg_not_running "CGroup Rules Engine Daemon"
+       fi
+}
+
+RETVAL=0
+# See how we are called
+case "$1" in
+  start)
+       start
+       RETVAL=$?
+       ;;
+  stop)
+       stop
+       RETVAL=$?
+       ;;
+  status)
+       status -p /var/run/cgred.pid cgred
+       RETVAL=$?
+       ;;
+  restart)
+       stop
+       start
+       ;;
+  condrestart)
+       if [ -f /var/lock/subsys/cgred ] ; then
+               stop
+               start
+       fi
+       ;;
+  reload|flash)
+       if [ -f /var/lock/subsys/cgred ] ; then
+               show "Reloading rules configuration..."
+               # SIGUSR2
+               kill -s 12 `cat ${pidfile}`
+               RETVAL=$?
+               if [ $RETVAL -eq 0 ] ; then
+                       fail
+               else
+                       ok
+               fi
+       else
+               msg_not_running "cgred"
+       fi
+       ;;
+  *)
+       msg_usage "$0 {start|stop|status|restart|condrestart|reload}"
+       exit 3
+       ;;
+esac
+
+exit $RETVAL
This page took 0.122428 seconds and 4 git commands to generate.