~ubuntu-branches/ubuntu/maverick/libcgroup/maverick-proposed

« back to all changes in this revision

Viewing changes to scripts/init.d/cgred.in

  • Committer: Bazaar Package Importer
  • Author(s): Dustin Kirkland
  • Date: 2009-08-26 11:29:17 UTC
  • Revision ID: james.westby@ubuntu.com-20090826112917-402ews2uj6v350d2
Tags: upstream-0.34
ImportĀ upstreamĀ versionĀ 0.34

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
#
 
3
# Start/Stop the CGroups Rules Engine Daemon
 
4
#
 
5
# Copyright Red Hat Inc. 2008
 
6
#
 
7
# Authors:      Steve Olivieri <sjo@redhat.com>
 
8
# This program is free software; you can redistribute it and/or modify it
 
9
# under the terms of version 2.1 of the GNU Lesser General Public License
 
10
# as published by the Free Software Foundation.
 
11
 
12
# This program is distributed in the hope that it would be useful, but
 
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
15
#
 
16
# cgred         CGroups Rules Engine Daemon
 
17
# chkconfig:    - 14 86
 
18
# description:  This is a daemon for automatically classifying processes \
 
19
#               into cgroups based on UID/GID.
 
20
#
 
21
# processname: cgrulesengd
 
22
# pidfile: /var/run/cgred.pid
 
23
#
 
24
### BEGIN INIT INFO
 
25
# Provides:             cgrulesengd
 
26
# Required-Start:       $local_fs $syslog $cgconfig
 
27
# Required-Stop:        $local_fs $syslog
 
28
# Should-Start:         
 
29
# Should-Stop:          
 
30
# Short-Description:    start and stop the cgroups rules engine daemon
 
31
# Description:          CGroup Rules Engine is a tool for automatically using \
 
32
#                       cgroups to classify processes
 
33
### END INIT INFO
 
34
 
 
35
prefix=@prefix@;exec_prefix=@exec_prefix@;sbindir=@sbindir@
 
36
CGRED_BIN=$sbindir/cgrulesengd
 
37
 
 
38
# Sanity checks
 
39
[ -x $CGRED_BIN ] || exit 1
 
40
 
 
41
# Source function library & LSB routines
 
42
. /etc/rc.d/init.d/functions
 
43
. /lib/lsb/init-functions
 
44
 
 
45
# Read in configuration options.
 
46
if [ -f "/etc/sysconfig/cgred.conf" ] ; then
 
47
        . /etc/sysconfig/cgred.conf
 
48
        OPTIONS="$NODAEMON $LOG"
 
49
        if [ -n "$LOG_FILE" ]; then
 
50
                OPTIONS="$OPTIONS --log-file=$LOG_FILE"
 
51
        fi
 
52
else
 
53
        OPTIONS=""
 
54
fi
 
55
 
 
56
# For convenience
 
57
processname=cgrulesengd
 
58
servicename=cgred
 
59
pidfile=/var/run/cgred.pid
 
60
 
 
61
RETVAL=0
 
62
 
 
63
start()
 
64
{
 
65
        echo $"Starting CGroup Rules Engine Daemon..."
 
66
        if [ -f "/var/lock/subsys/$servicename" ] ; then
 
67
                log_failure_msg "$servicename is already running with PID `cat ${pidfile}`"
 
68
                return 1
 
69
        fi
 
70
        daemon --check $servicename --pidfile $pidfile $CGRED_BIN $OPTIONS
 
71
        RETVAL=$?
 
72
        echo
 
73
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$servicename
 
74
        echo "`pidof $processname`" > $pidfile
 
75
}
 
76
 
 
77
stop()
 
78
{
 
79
        echo -n $"Stopping CGroup Rules Engine Daemon..."
 
80
        killproc -p $pidfile $processname -TERM
 
81
        RETVAL=$?
 
82
        echo
 
83
        if [ $RETVAL -eq 0 ] ; then
 
84
                rm -f /var/lock/subsys/$servicename
 
85
                rm -f $pidfile
 
86
        fi
 
87
        log_success_msg
 
88
}
 
89
 
 
90
# See how we are called
 
91
case "$1" in
 
92
        start)
 
93
                start
 
94
                ;;
 
95
        stop)
 
96
                stop
 
97
                ;;
 
98
        status)
 
99
                status -p $pidfile $processname
 
100
                RETVAL=$?
 
101
                ;;
 
102
        restart)
 
103
                stop
 
104
                start
 
105
                ;;
 
106
        condrestart)
 
107
                if [ -f /var/lock/subsys/$servicename ] ; then
 
108
                        stop
 
109
                        start
 
110
                fi
 
111
                ;;
 
112
        reload|flash)
 
113
                if [ -f /var/lock/subsys/$servicename ] ; then
 
114
                        echo $"Reloading rules configuration..."
 
115
                        kill -s 12 `cat ${pidfile}`
 
116
                        RETVAL=$?
 
117
                        if [ $RETVAL -eq 0 ] ; then
 
118
                                log_success_msg
 
119
                        else
 
120
                                log_failure_msg
 
121
                        fi
 
122
                else
 
123
                        log_failure_msg "$servicename is not running."
 
124
                fi
 
125
                ;;
 
126
        *)
 
127
                echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
 
128
                ;;
 
129
esac
 
130
 
 
131
exit $RETVAL