1 |
Author: ulm |
2 |
Date: 2009-06-05 19:07:36 +0000 (Fri, 05 Jun 2009) |
3 |
New Revision: 578 |
4 |
|
5 |
Modified: |
6 |
trunk/ChangeLog |
7 |
trunk/NEWS |
8 |
trunk/man/rc.eselect.5 |
9 |
trunk/modules/rc.eselect |
10 |
Log: |
11 |
Add "--unused" option to show status of scripts that are not assigned |
12 |
to any runlevel; bug 271208. Several small changes in the rc module. |
13 |
|
14 |
|
15 |
Modified: trunk/ChangeLog |
16 |
=================================================================== |
17 |
--- trunk/ChangeLog 2009-06-04 11:03:22 UTC (rev 577) |
18 |
+++ trunk/ChangeLog 2009-06-05 19:07:36 UTC (rev 578) |
19 |
@@ -1,3 +1,16 @@ |
20 |
+2009-06-05 Ulrich Mueller <ulm@g.o> |
21 |
+ |
22 |
+ * modules/rc.eselect (is_script): Symlinks are implicitly |
23 |
+ resolved, so no need to canonicalise. |
24 |
+ (do_start, do_stop, do_pause, do_reload, do_restart) |
25 |
+ (run_runscript): Move output message to calling functions. |
26 |
+ (do_list): Output colours also if only one runlevel is shown. |
27 |
+ (find_unused_scripts, show_script_status): New functions. |
28 |
+ (do_show): Add "--unused" option to show status of scripts that |
29 |
+ are not assigned to any runlevel; bug 271208. |
30 |
+ (describe_show_options): Document new option. |
31 |
+ * man/rc.eselect.5: Document new option for "show" action. |
32 |
+ |
33 |
2009-06-04 Ulrich Mueller <ulm@g.o> |
34 |
|
35 |
* modules/package-manager.eselect: New module, managing the |
36 |
|
37 |
Modified: trunk/NEWS |
38 |
=================================================================== |
39 |
--- trunk/NEWS 2009-06-04 11:03:22 UTC (rev 577) |
40 |
+++ trunk/NEWS 2009-06-05 19:07:36 UTC (rev 578) |
41 |
@@ -5,6 +5,8 @@ |
42 |
New features: |
43 |
- Add a test if the selected package manager is valid. |
44 |
- Extended syntax in editor-variable library. |
45 |
+ - The rc module can show the status of scripts that are not assigned to any |
46 |
+ runlevel (bug #271208). |
47 |
|
48 |
1.1: |
49 |
Bug fixes: |
50 |
|
51 |
Modified: trunk/man/rc.eselect.5 |
52 |
=================================================================== |
53 |
--- trunk/man/rc.eselect.5 2009-06-04 11:03:22 UTC (rev 577) |
54 |
+++ trunk/man/rc.eselect.5 2009-06-05 19:07:36 UTC (rev 578) |
55 |
@@ -2,7 +2,7 @@ |
56 |
.\" Distributed under the terms of the GNU General Public License v2 |
57 |
.\" $Id$ |
58 |
.\" |
59 |
-.TH rc.eselect 5 "May 2009" "Gentoo Linux" eselect |
60 |
+.TH rc.eselect 5 "June 2009" "Gentoo Linux" eselect |
61 |
.SH NAME |
62 |
rc.eselect \- Runlevel configuration module |
63 |
.SH SYNOPSIS |
64 |
@@ -185,9 +185,12 @@ |
65 |
and list them together with their status. If no |
66 |
.I runlevel |
67 |
is given, list the scripts from the current runlevel. |
68 |
-With option |
69 |
+With options |
70 |
.B --all |
71 |
-the scripts of all runlevels are shown. |
72 |
+or |
73 |
+.B --unused |
74 |
+the scripts of all runlevels or the scripts not assigned to any |
75 |
+runlevel are shown, respectively. |
76 |
|
77 |
# eselect rc show |
78 |
.br |
79 |
|
80 |
Modified: trunk/modules/rc.eselect |
81 |
=================================================================== |
82 |
--- trunk/modules/rc.eselect 2009-06-04 11:03:22 UTC (rev 577) |
83 |
+++ trunk/modules/rc.eselect 2009-06-05 19:07:36 UTC (rev 578) |
84 |
@@ -37,11 +37,10 @@ |
85 |
# list_runlevels PRIVATE |
86 |
# list runlevels for file $1 |
87 |
list_runlevels() { |
88 |
- [[ ${#@} -eq 1 ]] || return |
89 |
+ [[ $# -eq 1 ]] || return |
90 |
local x runlevels |
91 |
for x in ${ROOT}/etc/runlevels/* ; do |
92 |
- [[ -d ${x} ]] || continue |
93 |
- [[ -L ${ROOT}/etc/runlevels/${x##*/}/${1} ]] \ |
94 |
+ [[ -d ${x} && -L ${x}/${1} ]] \ |
95 |
&& runlevels=(${runlevels[@]} "${x##*/}") |
96 |
done |
97 |
echo -ne "${runlevels[@]}" |
98 |
@@ -51,38 +50,65 @@ |
99 |
# check if file $1 is a valid init script |
100 |
is_script() { |
101 |
local file=${1} |
102 |
- [[ -n ${file} ]] \ |
103 |
- || return 1 |
104 |
- ( [[ -L ${file} ]] \ |
105 |
- && [[ ! -e $(canonicalise -f ${file}) ]] ) \ |
106 |
- && return 1 |
107 |
- [[ -e ${file} ]] \ |
108 |
- && [[ ${file%%.sh} == ${file} ]] \ |
109 |
- && [[ ${file%%\~} == ${file} ]] \ |
110 |
- && [[ -n `grep "^#\!/sbin/runscript" ${file}` ]] |
111 |
+ [[ -n ${file} \ |
112 |
+ && ${file%%.sh} = ${file} \ |
113 |
+ && ${file%%\~} = ${file} \ |
114 |
+ && -e ${file} ]] \ |
115 |
+ && grep "^#\!/sbin/runscript" "${file}" &>/dev/null |
116 |
} |
117 |
|
118 |
# find_scripts PRIVATE |
119 |
# browse directory $1 for init scripts and return a list |
120 |
find_scripts() { |
121 |
- local ret |
122 |
for file in ${1}/* ; do |
123 |
- is_script ${file} \ |
124 |
- && ret=(${ret[@]} "${file##*/}") |
125 |
+ is_script ${file} && echo "${file##*/}" |
126 |
done |
127 |
- echo -ne ${ret[@]} |
128 |
} |
129 |
|
130 |
+# find_unused_scripts PRIVATE |
131 |
+# find scripts in /etc/init.d not belonging to any runlevel |
132 |
+find_unused_scripts() { |
133 |
+ local file x |
134 |
+ for file in $(find_scripts "${ROOT}/etc/init.d"); do |
135 |
+ for x in "${ROOT}"/etc/runlevels/*; do |
136 |
+ [[ -d ${x} && -L ${x}/${file} ]] && continue 2 |
137 |
+ done |
138 |
+ echo "${file##*/}" |
139 |
+ done |
140 |
+} |
141 |
+ |
142 |
+# show_script_status PRIVATE |
143 |
+# output list entry for script $1 and show its status |
144 |
+show_script_status() { |
145 |
+ local script=${1} status=unknown x |
146 |
+ |
147 |
+ for x in stopping starting inactive started stopped; do |
148 |
+ if service_${x} ${script}; then |
149 |
+ status=${x} |
150 |
+ break |
151 |
+ fi |
152 |
+ done |
153 |
+ case ${status} in |
154 |
+ stopped) |
155 |
+ write_kv_list_entry ${script} [${x}] |
156 |
+ ;; |
157 |
+ started) |
158 |
+ write_kv_list_entry ${script} "$(highlight [${x}])" |
159 |
+ ;; |
160 |
+ *) |
161 |
+ write_kv_list_entry ${script} "$(highlight_warning [${x}])" |
162 |
+ ;; |
163 |
+ esac |
164 |
+} |
165 |
+ |
166 |
# run_runscript PRIVATE |
167 |
# run RC_RUNSCRIPT with script $2- and command $1 |
168 |
run_runscript() { |
169 |
local command=${1} |
170 |
shift |
171 |
- write_list_start "${1}" |
172 |
- shift |
173 |
- for script in ${@} ; do |
174 |
- is_script ${ROOT}/etc/init.d/${script} \ |
175 |
- && /sbin/runscript ${ROOT}/etc/init.d/${script} ${command} |
176 |
+ for script in "$@"; do |
177 |
+ is_script "${ROOT}/etc/init.d/${script}" \ |
178 |
+ && /sbin/runscript "${ROOT}/etc/init.d/${script}" "${command}" |
179 |
done |
180 |
} |
181 |
|
182 |
@@ -102,7 +128,7 @@ |
183 |
} |
184 |
|
185 |
do_add() { |
186 |
- [[ ${#@} -gt 0 ]] \ |
187 |
+ [[ $# -gt 0 ]] \ |
188 |
|| die -q "Please specify the init script to be added!" |
189 |
local script=${1##*/} |
190 |
[[ -e ${ROOT}/etc/init.d/${script} ]] \ |
191 |
@@ -144,7 +170,7 @@ |
192 |
} |
193 |
|
194 |
do_delete() { |
195 |
- [[ ${#@} -gt 0 ]] \ |
196 |
+ [[ $# -gt 0 ]] \ |
197 |
|| die -q "Please specify the init script to be deleted!" |
198 |
local script=${1##*/} |
199 |
shift 1 |
200 |
@@ -194,12 +220,9 @@ |
201 |
die -q "${1} is no valid runlevel!" |
202 |
fi |
203 |
|
204 |
- for file in $(find_scripts ${dir}) ; do |
205 |
- [[ ${dir##*/} = init.d ]] \ |
206 |
- && write_kv_list_entry ${file} "$(list_runlevels ${file})" \ |
207 |
- || echo " ${file}" |
208 |
-# && echo " ${file} $(space $((20 - ${#file}))) | $(list_runlevels ${file})" \ |
209 |
-# || echo " ${file}" |
210 |
+ for file in $(find_scripts "${dir}") ; do |
211 |
+ write_kv_list_entry "${file}" \ |
212 |
+ $([[ ${dir##*/} = init.d ]] && list_runlevels "${file}") |
213 |
done |
214 |
} |
215 |
|
216 |
@@ -216,10 +239,11 @@ |
217 |
describe_show_options() { |
218 |
echo "runlevels : Runlevels to list (defaults to current runlevel)" |
219 |
echo "--all : List all runlevels" |
220 |
+ echo "--unused : Show scripts not assigned to any runlevel" |
221 |
} |
222 |
|
223 |
do_show() { |
224 |
- local runlevel status n x |
225 |
+ local runlevel all unused n x |
226 |
|
227 |
# core.bash redefines eval; unset it because OpenRC's |
228 |
# functions.sh needs the bash builtin |
229 |
@@ -228,43 +252,46 @@ |
230 |
|
231 |
if [[ $# -eq 0 ]]; then |
232 |
set -- "$(get_runlevel)" |
233 |
- elif [[ ${1##--} = all ]]; then |
234 |
- for x in "${ROOT}"/etc/runlevels/*; do |
235 |
- [[ -d "${x}" ]] && runlevels=("${runlevels[@]}" "${x##*/}") |
236 |
+ else |
237 |
+ while [[ $# -gt 0 ]]; do |
238 |
+ case ${1##--} in |
239 |
+ all) all=1 ;; |
240 |
+ unused) unused=1 ;; |
241 |
+ *) break ;; |
242 |
+ esac |
243 |
+ shift |
244 |
done |
245 |
- set -- "${runlevels[@]}" |
246 |
+ if [[ -n ${all} ]]; then |
247 |
+ local runlevels=() |
248 |
+ for x in "${ROOT}"/etc/runlevels/*; do |
249 |
+ [[ -d "${x}" ]] && runlevels=("${runlevels[@]}" "${x##*/}") |
250 |
+ done |
251 |
+ set -- "${runlevels[@]}" |
252 |
+ fi |
253 |
fi |
254 |
|
255 |
for runlevel in "$@"; do |
256 |
[[ -n ${runlevel} && -d ${ROOT}/etc/runlevels/${runlevel} ]] \ |
257 |
|| die -q "\"${runlevel}\" is no valid runlevel" |
258 |
|
259 |
- write_list_start \ |
260 |
- "Status of init scripts in runlevel \"${runlevel}\"" |
261 |
+ write_list_start "Status of init scripts in runlevel \"${runlevel}\"" |
262 |
n=0 |
263 |
for script in $(find_scripts "${ROOT}/etc/runlevels/${runlevel}"); do |
264 |
- status=unknown |
265 |
- for x in stopping starting inactive started stopped; do |
266 |
- if service_${x} ${script}; then |
267 |
- status=${x} |
268 |
- break |
269 |
- fi |
270 |
- done |
271 |
- case ${status} in |
272 |
- stopped) |
273 |
- write_kv_list_entry ${script} [${x}] |
274 |
- ;; |
275 |
- started) |
276 |
- write_kv_list_entry ${script} "$(highlight [${x}])" |
277 |
- ;; |
278 |
- *) |
279 |
- write_kv_list_entry ${script} "$(highlight_warning [${x}])" |
280 |
- ;; |
281 |
- esac |
282 |
+ show_script_status ${script} |
283 |
((n++)) |
284 |
done |
285 |
[[ ${n} -eq 0 ]] && write_kv_list_entry "(none found)" "" |
286 |
done |
287 |
+ |
288 |
+ if [[ -n ${unused} ]]; then |
289 |
+ write_list_start "Status of init scripts not assigned to any runlevel" |
290 |
+ n=0 |
291 |
+ for script in $(find_unused_scripts); do |
292 |
+ show_script_status ${script} |
293 |
+ ((n++)) |
294 |
+ done |
295 |
+ [[ ${n} -eq 0 ]] && write_kv_list_entry "(none found)" "" |
296 |
+ fi |
297 |
} |
298 |
|
299 |
### start action |
300 |
@@ -282,9 +309,10 @@ |
301 |
} |
302 |
|
303 |
do_start() { |
304 |
- [[ ${#@} -gt 0 ]] \ |
305 |
+ [[ $# -gt 0 ]] \ |
306 |
|| die -q "Please specify the init script to be started!" |
307 |
- run_runscript start "Starting init script$([[ ${#@} -gt 1 ]] && echo -ne 's')" ${@} |
308 |
+ write_list_start "Starting init script$([[ $# -gt 1 ]] && echo -n 's')" |
309 |
+ run_runscript start "$@" |
310 |
} |
311 |
|
312 |
### stop action |
313 |
@@ -302,9 +330,10 @@ |
314 |
} |
315 |
|
316 |
do_stop() { |
317 |
- [[ ${#@} -gt 0 ]] \ |
318 |
+ [[ $# -gt 0 ]] \ |
319 |
|| die -q "Please specify the init script to be stopped!" |
320 |
- run_runscript stop "Stopping init script$([[ ${#@} -gt 1 ]] && echo -ne 's')" ${@} |
321 |
+ write_list_start "Stopping init script$([[ $# -gt 1 ]] && echo -n 's')" |
322 |
+ run_runscript stop "$@" |
323 |
} |
324 |
|
325 |
### pause action |
326 |
@@ -322,9 +351,10 @@ |
327 |
} |
328 |
|
329 |
do_pause() { |
330 |
- [[ ${#@} -gt 0 ]] \ |
331 |
+ [[ $# -gt 0 ]] \ |
332 |
|| die -q "Please specify the init script to be paused!" |
333 |
- run_runscript pause "Pausing init script$([[ ${#@} -gt 1 ]] && echo -ne 's')" ${@} |
334 |
+ write_list_start "Pausing init script$([[ $# -gt 1 ]] && echo -n 's')" |
335 |
+ run_runscript pause "$@" |
336 |
} |
337 |
|
338 |
### reload action |
339 |
@@ -342,9 +372,10 @@ |
340 |
} |
341 |
|
342 |
do_reload() { |
343 |
- [[ ${#@} -gt 0 ]] \ |
344 |
+ [[ $# -gt 0 ]] \ |
345 |
|| die -q "Please specify the init script to be reloaded!" |
346 |
- run_runscript reload "Reloading init script$([[ ${#@} -gt 1 ]] && echo -ne 's')" ${@} |
347 |
+ write_list_start "Reloading init script$([[ $# -gt 1 ]] && echo -n 's')" |
348 |
+ run_runscript reload "$@" |
349 |
} |
350 |
|
351 |
### restart action |
352 |
@@ -362,9 +393,10 @@ |
353 |
} |
354 |
|
355 |
do_restart() { |
356 |
- [[ ${#@} -gt 0 ]] \ |
357 |
+ [[ $# -gt 0 ]] \ |
358 |
|| die -q "Please specify the init script to be restarted!" |
359 |
- run_runscript restart "Restarting init script$([[ ${#@} -gt 1 ]] && echo -ne 's')" ${@} |
360 |
+ write_list_start "Restarting init script$([[ $# -gt 1 ]] && echo -n 's')" |
361 |
+ run_runscript restart "$@" |
362 |
} |
363 |
|
364 |
# vim: set ft=eselect : |