]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/init.d/cpusets
- use $() for command substitution
[projects/rc-scripts.git] / rc.d / init.d / cpusets
1 #!/bin/sh
2 #
3 # cpusets       Create/remove cpusets
4 #
5 # chkconfig:    12345 01 99
6 # description:  Creates/Removes all cpu sets configured to \
7 #               start at boot time.
8 #
9 # probe:        true
10
11 # $Id$
12
13 . /etc/sysconfig/system
14
15 if [ "${CPUSETS:-no}" = "no" ]; then
16         case "$1" in
17         start|stop|restart)
18                 exit 0
19                 ;;
20         esac
21 fi
22
23 # Source function library.
24 . /etc/rc.d/init.d/functions
25
26 if is_yes "${CPUSETS}" && ! grep -q "/dev/cpuset" /proc/mounts ; then
27         nls "ERROR: CPUSET support not enabled in kernel or /dev/cpuset not mounted" >&2
28         exit 1
29 fi
30
31 cpuset_create()
32 {
33         local CPUS MEMS CPU_EXCLUSIVE MEM_EXCLUSIVE NOTIFY_ON_RELEASE TASKS
34
35         . /etc/sysconfig/cpusets/cpuset-$i
36
37         if mkdir /dev/cpuset/"$NAME" >/dev/null 2>&1 ; then
38                 [ -n "$CPUS" ] && echo "$CPUS" >/dev/cpuset/"$NAME"/cpus
39                 [ -n "$MEMS" ] && echo "$MEMS" >/dev/cpuset/"$NAME"/mems
40                 [ -n "$CPU_EXCLUSIVE" ] && echo "$CPU_EXCLUSIVE" >/dev/cpuset/"$NAME"/cpu_exclusive
41                 [ -n "$MEM_EXCLUSIVE" ] && echo "$MEM_EXCLUSIVE" >/dev/cpuset/"$NAME"/mem_exclusive
42                 [ -n "$NOTIFY_ON_RELEASE" ] && echo "$NOTIFY_ON_RELEASE" >/dev/cpuset/"$NAME"/notify_on_release
43                 [ -n "$VIRTUALIZE" ] && echo "$VIRTUALIZE" >/dev/cpuset/"$NAME"/virtualize
44                 [ -n "$TASKS" ] && echo "$TASKS" >/dev/cpuset/"$NAME"/tasks
45                 return 0
46         fi
47         return 1
48 }
49
50 cpuset_remove()
51 {
52         local CPUS MEMS CPU_EXCLUSIVE MEM_EXCLUSIVE NOTIFY_ON_RELEASE TASKS
53
54         . /etc/sysconfig/cpusets/cpuset-$i
55
56         # This MUST be rmdir (not rm -rf)
57         if rmdir /dev/cpuset/"$NAME" >/dev/null 2>&1 ; then
58                 return 0
59         else
60                 return 1
61         fi
62 }
63
64 cpuset_empty()
65 {
66         if [ $(cat /dev/cpuset/$1/tasks 2>/dev/null | wc -c) -eq 0 ] ; then
67                 # true returns zero
68                 return 0
69         else
70                 # false returns one
71                 return 1
72         fi
73 }
74
75 start() {
76         rc_splash "bootcpusets start"
77
78         for i in $cpusets_boot; do
79                 show "$(nls -n "Creating cpuset %s" "$i")"
80                 if cpuset_create $i ; then
81                         ok
82                 else
83                         fail
84                 fi
85         done
86
87         touch /var/lock/subsys/cpusets
88 }
89
90 stop() {
91         for i in $cpusets_boot; do
92                 show "$(nls -n "Removing cpuset %s" "$i")"
93                 busy
94                 if cpuset_empty $i; then
95                         if cpuset_remove $i; then
96                                 ok
97                         else
98                                 fail
99                         fi
100                 else
101                         fail
102                 fi
103         done
104
105         rm -f /var/lock/subsys/cpusets
106 }
107
108 # Get list of config files
109 # ignores editor backup files and rpm blackups
110 cpuset_configs()
111 {
112         local match="$1"
113         for a in /etc/sysconfig/cpusets/$match; do
114                 case "$a" in
115                 *rpmorig|*rpmnew|*rpmsave|*~|*.orig)
116                         continue
117                         ;;
118                 *)
119                         echo $a
120                 ;;
121                 esac
122         done
123 }
124
125 cpuset_files="$(cpuset_configs 'cpuset-*')"
126 cpusets_boot=$(
127         for i in $cpuset_files; do
128                 ONBOOT=""; . "$i" 2>/dev/null
129                 is_yes "$ONBOOT" && echo "${i##*/cpuset-}"
130         done
131 )
132
133 # See how we were called.
134 case "$1" in
135   start)
136         start
137         ;;
138   stop)
139         stop
140         ;;
141   status)
142         nls "Configured cpusets:"
143         echo "$cpusets_boot"
144         echo
145         nls "Currently empty cpusets:"
146         for i in $(ls /dev/cpuset 2>/dev/null); do
147                 if [ -d /dev/cpuset/$i ]; then
148                         cpuset_empty $i && echo $i
149                 fi
150         done
151         echo
152         nls "Currently active cpusets:"
153         for i in $(ls /dev/cpuset 2>/dev/null); do
154                 if [ -d /dev/cpuset/$i ]; then
155                         cpuset_empty $i || echo $i
156                 fi
157         done
158         echo
159         ;;
160   restart)
161         stop
162         start
163         ;;
164   *)
165         msg_usage "$0 {start|stop|restart|status}"
166         exit 3
167 esac
168
169 exit 0
This page took 0.062777 seconds and 3 git commands to generate.