-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitd_oomscored
executable file
·146 lines (134 loc) · 2.77 KB
/
initd_oomscored
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
#!/bin/bash
#
# Start/Stop the OOM Score Daemon
#
# oomscored OOM Score Daemon
# chkconfig: - 14 86
# description: Service to automatically set oom_score_adj for processes on a system
#
# processname: oomscored
# pidfile: /var/run/oomscored.pid
#
### BEGIN INIT INFO
# Provides: oomscored
# Required-Start: $local_fs $remote_fs $syslog
# Required-Stop: $local_fs $remote_fs $syslog
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 5
# Default-Stop: 0 1 6
# Short-Description: start and stop the oom score daemon
# Description: Service to automatically set oom_score_adj for processes on a system
### END INIT INFO
#FIXME: This is pretty ugly. How do we want to locate the script?
prefix=/usr;exec_prefix=/usr;sbindir=/usr/sbin
OOMSCORED_BIN=$sbindir/oomscoreadj.py
OOMSCORED_CONF=/etc/oomrules.conf
# Sanity checks
[ -x $OOMSCORED_BIN ] || exit 1
. /lib/lsb/init-functions
# Read in configuration options.
LOG_FILE=""
if [ -f "/etc/sysconfig/oomscored" ] ; then
. /etc/sysconfig/oomscored
OPTIONS="$OOMSCORED_OPTIONS"
else
OPTIONS=""
fi
# For convenience
processname=oomscoreadj.py
servicename=oomscored
pidfile=/var/run/oomscored.pid
start()
{
if [ -f "$pidfile" ]; then
pid=$(pgrep -f -F $pidfile 'python.*'"$OOMSCORED_BIN")
if [ $? -ne 1 ]; then
log_warning_msg "Removing stale lock file $pidfile"
rm -f "$pidfile"
else
log_failure_msg "$servicename is already running with PID `cat ${pidfile}`"
return 1
fi
fi
startproc -l $LOG_FILE -p $pidfile /usr/bin/python $OOMSCORED_BIN $OPTIONS
retval=$?
if [ $retval -ne 0 ]; then
return 7
fi
pid=$(pgrep -f 'python.*'"$OOMSCORED_BIN")
echo $pid > $pidfile
return 0
}
stop()
{
if [ ! -f $pidfile ]; then
log_success_msg
return 0
fi
pkill -TERM -f -F $pidfile 'python.*'"$OOMSCORED_BIN"
retval=$?
if [ $retval -ne 0 ]; then
return 1
fi
rm -f "$pidfile"
return 0
}
RETVAL=0
# See how we are called
case "$1" in
start)
echo -n "Starting OOM Score Daemon"
start
RETVAL=$?
rc_status -v
;;
stop)
echo -n "Stopping OOM Score Daemon"
stop
RETVAL=$?
rc_status -v
;;
status)
echo -n "Checking for OOM Score Daemon"
RETVAL=1
if [ -f "$pidfile" ]; then
pid=$(pgrep -f -F $pidfile 'python.*'"$OOMSCORED_BIN")
RETVAL=$?
fi
if [ $RETVAL -ne 0 ] ; then
rc_failed 3
RETVAL=3
fi
rc_status -v
;;
restart)
stop
start
RETVAL=$?
rc_status
;;
condrestart)
if [ -f "$pidfile" ]; then
stop
start
RETVAL=$?
fi
rc_status
;;
reload|flash)
if [ -f "$pidfile" ]; then
echo -n "Reloading rules configuration..."
pkill -SIGUSR1 -f -F $pidfile 'python.*'"$OOMSCORED_BIN"
else
echo "$servicename is not running."
rc_failed 7
fi
rc_status -v
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
RETVAL=2
;;
esac
exit $RETVAL