Subversion Repositories configs

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 - 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:	- 30 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=/usr;exec_prefix=/usr;sbindir=/sbin
36
CGRED_BIN=$sbindir/cgrulesengd
37
CGRED_CONF=/etc/cgrules.conf
38
 
39
# Sanity checks
40
[ -x $CGRED_BIN ] || exit 1
41
 
42
# Source function library & LSB routines
43
. /etc/rc.d/init.d/functions
44
log_success_msg () {
45
    echo -n $*; success "$*"; echo
46
}
47
log_failure_msg () {
48
    echo -n $*; failure "$*"; echo
49
}
50
log_warning_msg () {
51
    echo -n $*; warning "$*"; echo
52
}
53
 
54
# Read in configuration options.
55
if [ -f "/etc/sysconfig/cgred.conf" ] ; then
56
	. /etc/sysconfig/cgred.conf
57
	OPTIONS="$NODAEMON $LOG"
58
	if [ -n "$LOG_FILE" ]; then
59
		OPTIONS="$OPTIONS --logfile=$LOG_FILE"
60
	fi
61
	if [ -n "$SOCKET_USER" ]; then
62
		OPTIONS="$OPTIONS -u $SOCKET_USER"
63
	fi
64
	if [ -n "$SOCKET_GROUP" ]; then
65
		OPTIONS="$OPTIONS -g $SOCKET_GROUP"
66
	fi
67
else
68
	OPTIONS=""
69
fi
70
 
71
# For convenience
72
processname=cgrulesengd
73
servicename=cgred
74
lockfile="/var/lock/subsys/$servicename"
75
pidfile=/var/run/cgred.pid
76
 
77
start()
78
{
79
	echo -n $"Starting CGroup Rules Engine Daemon: "
80
	if [ -f "$lockfile" ]; then
81
		log_failure_msg "$servicename is already running with PID `cat ${pidfile}`"
82
		return 0
83
	fi
84
	if ! grep "^cgroup" /proc/mounts &>/dev/null; then
85
		echo
86
		log_failure_msg $"Cannot find cgroups, is cgconfig service running?"
87
		return 1
88
	fi
89
	daemon --check $servicename --pidfile $pidfile $CGRED_BIN $OPTIONS
90
	retval=$?
91
	echo
92
	if [ $retval -ne 0 ]; then
93
		return 7
94
	fi
95
	touch "$lockfile"
96
	if [ $? -ne 0 ]; then
97
		return 1
98
	fi
99
	echo "`pidof $processname`" > $pidfile
100
	[[ -x /sbin/restorecon ]] && /sbin/restorecon $pidfile
101
	return 0
102
}
103
 
104
stop()
105
{
106
	echo -n $"Stopping CGroup Rules Engine Daemon..."
107
	if [ ! -f $pidfile ]; then
108
		log_success_msg
109
		return 0
110
	fi
111
	killproc -p $pidfile -TERM "$processname"
112
	retval=$?
113
	echo
114
	if [ $retval -ne 0 ]; then
115
		return 1
116
	fi
117
	rm -f "$lockfile" "$pidfile"
118
	return 0
119
}
120
 
121
RETVAL=0
122
 
123
# See how we are called
124
case "$1" in
125
	start)
126
		start
127
		RETVAL=$?
128
		;;
129
	stop)
130
		stop
131
		RETVAL=$?
132
		;;
133
	status)
134
		status -p $pidfile $servicename
135
		RETVAL=$?
136
		;;
137
	restart)
138
		stop
139
		start
140
		RETVAL=$?
141
		;;
142
	condrestart)
143
		if [ -f "$lockfile" ]; then
144
			stop
145
			start
146
			RETVAL=$?
147
		fi
148
		;;
149
	reload|flash)
150
		if [ -f "$lockfile" ]; then
151
			echo $"Reloading rules configuration..."
152
			kill -s 12 `cat ${pidfile}`
153
			RETVAL=$?
154
			if [ $RETVAL -eq 0 ] ; then
155
				log_success_msg
156
			else
157
				log_failure_msg
158
			fi
159
		else
160
			log_failure_msg "$servicename is not running."
161
		fi
162
		;;
163
	*)
164
		echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
165
		RETVAL=2
166
		;;
167
esac
168
 
169
exit $RETVAL