Debian Codegraph @

stap-server

raw
1 #!/bin/bash
2 #
3 # stap-server script for managing the systemtap compile server
4 #
5 # Copyright (C) 2008-2011 Red Hat Inc.
6 #
7 # This file is part of systemtap, and is free software. You can
8 # redistribute it and/or modify it under the terms of the GNU General
9 # Public License (GPL); either version 2, or (at your option) any
10 # later version.
11 #
12 # This script provides management of systemtap compile servers as a service.
13 # See stap-server(8) for more information.
14
15 if [ -f /etc/rc.d/init.d/functions ]; then
16 # Red Hat init functions
17 . /etc/rc.d/init.d/functions
18 else
19 # Default init functions
20 success () {
21 echo -n "OK"
22 }
23 failure () {
24 echo -n "FAILED"
25 }
26 fi
27
28 # Systemtap function library
29 . ${PKGLIBEXECDIR}stap-env
30
31 prog=stap-server
32
33 # Commands
34 STAP_START_SERVER=${stap_pkglibexecdir}stap-start-server
35 STAP_STOP_SERVER=${stap_pkglibexecdir}stap-stop-server
36 UNAME=/bin/uname
37
38 # Default Global Configuration
39 CONFIG_FILE=$stap_sysconfdir/sysconfig/stap-server
40 CONFIG_PATH=$stap_sysconfdir/stap-server/conf.d
41 STAT_PATH=$stap_localstatedir/run/stap-server
42 LOG_FILE=$stap_localstatedir/log/stap-server/log
43
44 # Default option settings
45 # Optional global config file
46 OPT_CONFIG_FILE=
47 OPT_OTHER=
48
49 OPT_PORT_IX=0
50 OPT_LOG_IX=0
51 OPT_SSL_IX=0
52 OPT_MAXTHREADS_IX=0
53 OPT_MAXREQSIZE_IX=0
54 OPT_MAXCOMPRESSEDREQ_IX=0
55
56 echo_usage () {
57 echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|status} [options]"
58 echo $"Options:"
59 echo $" -c configfile : specify additional global configuration file."
60 echo $" -a arch : specify the target architecture."
61 echo $" -r release : specify a kernel release."
62 echo $" -I path : augment the search path for tapsets."
63 echo $" -R path : specify the location of the systemtap runtime."
64 echo $" -B options : specify 'make' options for building systemtap modules."
65 echo $" -D name[=value] : add a macro definition for building systemtap modules."
66 echo $" -u username : specify the user who will run the server(s)."
67 echo $" -i : specify a server that handles all installed kernel releases."
68 echo $" -n nickname : specify a server configuration by nickname."
69 echo $" -p pid : specify a server or server configuration by process id."
70 echo $" -P : use a password for the server's NSS certificate database."
71 echo $" -k : keep server temporary files."
72 echo $" --port port : specify the network port to be used by the server."
73 echo $" --log path : specify the location of the server's log file."
74 echo $" --ssl path : specify the location of the server's certificate database."
75 echo $" --max-threads threads : specify the maximum number of worker threads to handle concurrent requests."
76 echo $" --max-request-size size : specify the maximum size of an uncompressed client request in bytes."
77 echo $" --max-compressed-request size : specify the maximum size of an compressed client request in bytes."
78 echo $""
79 echo $"All options may be specified more than once."
80 echo $""
81 echo $"If -a is not specified, the default architecture is that of the host"
82 echo $"platform."
83 echo $""
84 echo $"If -r is not specified, the default kernel release is that currently"
85 echo $"running on the host platform."
86 echo $""
87 echo $"If -u is not specified, the default user is 'stap-server'"
88 echo $""
89 echo $"If --port is not specified, the default is to use a randomly selected port."
90 echo $""
91 echo $"If --log is not specified, the default is '$stap_localstatedir/log/stap-server/log'."
92 echo $""
93 echo $"If --ssl is not specified, the default is '$stap_sysconfdir/ssl/server'."
94 echo $""
95 echo $"If --max-threads is not specified, the default is the number of processors."
96 echo $""
97 echo $"If --max-threads is specified with a value of 0, all requests are handled in the main thread."
98 echo $""
99 echo $"If --max-request-size is not specified, the default value is 50000 bytes."
100 echo $""
101 echo $"If --max-compressed-request is not specified, the default value is 5000 bytes."
102 echo $""
103 echo $"Each -D, -I and -B option specifies an additional macro, path or option respectively"
104 echo $"to be applied to subsequent servers specified."
105 echo $""
106 echo $"Each --port, --log, --ssl, --max-threads, --max-request-size, and"
107 echo $"--max-compressed-request option is added to an option-specific list"
108 echo $"which will be applied, in turn, to each server specified. If more "
109 echo $"servers are specified than options in a given list, the default for that"
110 echo $"option will be used for subsequent servers."
111 echo $""
112 echo $"For other options, each new instance overrides the previous setting."
113 echo $""
114 echo $"The -i option is a shortcut which specifies a server that handles every"
115 echo $"release installed in /lib/modules/."
116 echo $""
117 echo $"The -n option allows the specification of a server configuration by"
118 echo $"nickname. When -n is specified, a currently running server with the"
119 echo $"given nickname will be searched for. If no currently running server"
120 echo $"with the given nickname is found, a server configuration with the"
121 echo $"given nickname will be searched for in"
122 echo $"$stap_sysconfdir/stap-server/conf.d/*.conf."
123 echo $"If a server configuration for the given nickname is found, the -a, -r,"
124 echo $"-D, -I, -R, -B and -u options for that server will be used as if they were"
125 echo $"specified on the command line. If no configuration with the given"
126 echo $"nickname is found, and the action is 'start' (or an action behaving"
127 echo $"like 'start' (see below)), the server will be started with the given"
128 echo $"nickname. If no configuration with the given nickname is found, and"
129 echo $"the action is not 'start' (or an action behaving" "like 'start',"
130 echo $"it is an error. If a nickname is not specified for a server, its"
131 echo $"nickname will be its process id."
132 echo $""
133 echo $"The -p option allows the specification of a server configuration by"
134 echo $"process id. When -p is specified, a currently running server with the"
135 echo $"given process id will be searched for. If no such server is found,"
136 echo $"it is an error. If a server with the given pid is found, the -a, -r,"
137 echo $"-D, -I, -R, -B and -u options for that server will be used as if they were"
138 echo $"specified on the command line."
139 echo $""
140 echo $"The -k option tells the server to keep the temporary directories it creates"
141 echo $"during each transaction with a client."
142 echo $""
143 echo $"The specified action is performed for the server(s) specified on the"
144 echo $"command line. If no servers are specified on the command line, the"
145 echo $"behavior is as follows:"
146 echo $""
147 echo $" start: Start the servers configured in $stap_sysconfdir/stap-server/conf.d/*.conf."
148 echo $" If none are configured, start a server for the kernel release"
149 echo $" and architecture of the host platform."
150 echo $""
151 echo $" stop: Stop all currently running servers."
152 echo $""
153 echo $" restart: Restart all currently running servers. If no servers are running,"
154 echo $" behave as if 'start' was specified."
155 echo $""
156 echo $" condrestart: Restart all currently running servers. If no servers are running,"
157 echo $" do nothing."
158 echo $""
159 echo $" try-restart: Same as condrestart."
160 echo $""
161 echo $" force-reload: Stop all currently running servers and behave as if 'start'"
162 echo $" was specified."
163 echo $""
164 echo $" status: Report the status of all current running servers."
165 echo $""
166 }
167
168 #-----------------------------------------------------------------
169 # Helper functions
170 #-----------------------------------------------------------------
171 log () { # message
172 echo `LC_ALL=en date +"%b %e %T"`": $1" >> "$LOG_FILE"
173 }
174 clog () { # message [-n]
175 echo $2 "$1"
176 log "$1"
177 }
178 slog () { # message
179 logger "$1" # if syslogd is running, this message will be sent to syslog.
180 log "$1"
181 }
182 logex () { # command
183 eval log \"Exec: "$@"\"
184 "$@" >> "$LOG_FILE" 2>&1
185 return $?
186 }
187 do_failure () { # message
188 slog "Error: $1"
189 failure "$1"
190 }
191 do_success () { # message
192 log "Pass: $1"
193 success "$1"
194 }
195
196 #------------------------------------------------------------------
197 # Parameter parsing and setup options
198 #------------------------------------------------------------------
199 parse_args () { # arguments
200 local rc=0
201 while [ -n "$1" ]; do
202 case "$1" in
203 -k | -P)
204 OPT_OTHER="$OPT_OTHER $1"
205 shift 1
206 ;;
207 -a)
208 SERVER_CMDS+=("ARCH=\"`quote_for_cmd "$2"`\"")
209 shift 1
210 ;;
211 -B)
212 SERVER_CMDS+=("BUILD+=(\"`quote_for_cmd "$2"`\")")
213 shift 1
214 ;;
215 -c)
216 OPT_CONFIG_FILE="$2"
217 shift 1
218 ;;
219 -i)
220 process_i
221 ;;
222 -D)
223 SERVER_CMDS+=("DEFINE+=(\"`quote_for_cmd "$2"`\")")
224 shift 1
225 ;;
226 -I)
227 SERVER_CMDS+=("INCLUDE+=(\"`quote_for_cmd "$2"`\")")
228 shift 1
229 ;;
230 -n)
231 process_n "$2"
232 shift 1
233 ;;
234 -p)
235 process_p "$2"
236 test $? = 0 || rc=1
237 shift 1
238 ;;
239 -r)
240 process_r "$2"
241 test $? = 0 || rc=1
242 shift 1
243 ;;
244 -R)
245 SERVER_CMDS+=("RUNTIME=\"`quote_for_cmd "$2"`\"")
246 shift 1
247 ;;
248 -u)
249 SERVER_CMDS+=("USER=\"`quote_for_cmd "$2"`\"")
250 shift 1
251 ;;
252 --log)
253 OPT_LOG+=("$2")
254 shift 1
255 ;;
256 --port)
257 OPT_PORT+=("$2")
258 shift 1
259 ;;
260 --ssl)
261 OPT_SSL+=("$2")
262 shift 1
263 ;;
264 --max-threads)
265 OPT_MAXTHREADS+=("$2")
266 shift 1
267 ;;
268 --max-request-size)
269 OPT_MAXREQSIZE+=("$2")
270 shift 1
271 ;;
272 --max-compressed-request)
273 OPT_MAXCOMPRESSEDREQ+=("$2")
274 shift 1
275 ;;
276 --)
277 ;;
278 *)
279 rc=1
280 ;;
281 esac
282 shift 1
283 done
284
285 # Add options from any lists and an EXEC command to the end if any server options were specified
286 if test -n "$SERVER_CMDS"; then
287 add_distributed_options
288 SERVER_CMDS+=("EXEC")
289 fi
290
291 test $rc != 0 && echo_usage
292 return $rc
293 }
294
295 # Some options accumulate into lists when specified more than once. The items in the each list
296 # are the applied to each specified server in turn. If a list runs out, then the default for that
297 # option is applied.
298 add_distributed_options () {
299 # The --log option
300 if test -n "${OPT_LOG[$OPT_LOG_IX]}"; then
301 SERVER_CMDS+=("LOG=\"`quote_for_cmd "${OPT_LOG[$OPT_LOG_IX]}"`\"")
302 OPT_LOG_IX=$(($OPT_LOG_IX + 1))
303 else
304 SERVER_CMDS+=("LOG=\"`quote_for_cmd "$LOG_FILE"`\"")
305 fi
306 # The --port option
307 if test -n "${OPT_PORT[$OPT_PORT_IX]}"; then
308 SERVER_CMDS+=("PORT=\"`quote_for_cmd "${OPT_PORT[$OPT_PORT_IX]}"`\"")
309 OPT_PORT_IX=$(($OPT_PORT_IX + 1))
310 else
311 SERVER_CMDS+=("PORT=\"\"")
312 fi
313 # The --ssl option
314 if test -n "${OPT_SSL[$OPT_SSL_IX]}"; then
315 SERVER_CMDS+=("SSL=\"`quote_for_cmd "${OPT_SSL[$OPT_SSL_IX]}"`\"")
316 OPT_SSL_IX=$(($OPT_SSL_IX + 1))
317 else
318 SERVER_CMDS+=("SSL=\"\"")
319 fi
320 # The --max-threads option
321 if test -n "${OPT_MAXTHREADS[$OPT_MAXTHREADS_IX]}"; then
322 SERVER_CMDS+=("MAXTHREADS=\"`quote_for_cmd "${OPT_MAXTHREADS[$OPT_MAXTHREADS_IX]}"`\"")
323 OPT_MAXTHREADS_IX=$(($OPT_MAXTHREADS_IX + 1))
324 else
325 SERVER_CMDS+=("MAXTHREADS=\"\"")
326 fi
327 # The --max-request-size option
328 if test -n "${OPT_MAXREQSIZE[$OPT_MAXREQSIZE_IX]}"; then
329 SERVER_CMDS+=("MAXREQSIZE=\"`quote_for_cmd "${OPT_MAXREQSIZE[$OPT_MAXREQSIZE_IX]}"`\"")
330 OPT_MAXREQSIZE_IX=$(($OPT_MAXREQSIZE_IX + 1))
331 else
332 SERVER_CMDS+=("MAXREQSIZE=\"\"")
333 fi
334 # The --max-compressed-request option
335 if test -n "${OPT_MAXCOMPRESSEDREQ[$OPT_MAXCOMPRESSEDREQ_IX]}"; then
336 SERVER_CMDS+=("MAXCOMPRESSEDREQ=\"`quote_for_cmd "${OPT_MAXCOMPRESSEDREQ[$OPT_MAXCOMPRESSEDREQ_IX]}"`\"")
337 OPT_MAXCOMPRESSEDREQ_IX=$(($OPT_MAXCOMPRESSEDREQ_IX + 1))
338 else
339 SERVER_CMDS+=("MAXCOMPRESSEDREQ=\"\"")
340 fi
341 }
342
343 # Process the -i flag.
344 process_i () {
345 cd /lib/modules
346 local release
347 for release in `ls`; do
348 process_r $release
349 done
350 return 0
351 }
352
353 # Process the -n flag.
354 process_n () {
355 local target_NICKNAME="$1"
356
357 # Is there a running server with this nickname?
358 local pid=`get_server_pid_by_nickname "$target_NICKNAME"`
359 if [ -n "$pid" ]; then
360 # Read the configuration and add it to the configuration commands.
361 interpret_server_status "$STAT_PATH/$pid.stat" || continue
362 add_server_commands
363 return
364 fi
365
366 # Is there a server configuration with this nickname?
367 for f in "$CONFIG_PATH"/*.conf; do
368 if [ -f "$f" ]; then
369 interpret_server_config "$f" || continue
370 test "X$NICKNAME" = "X$target_NICKNAME" || continue
371 add_server_commands
372 return
373 fi
374 done
375
376 # No server configuration could be found for this nickname. Add a
377 # NICKNAME_NOT_FOUND=... command to the configuration commands.
378 SERVER_CMDS+=("NICKNAME_NOT_FOUND=\"`quote_for_cmd "$target_NICKNAME"`\"")
379 }
380
381 # Process the -p flag.
382 process_p () {
383 local pid="$1"
384
385 # Are we managing a server with the given pid?
386 test ! -f "$STAT_PATH/$pid.stat" && echo "No stap-server running as pid $pid" && \
387 exit 1
388
389 # Add the configuration of the server running as $pid to SERVER_CMDS
390 interpret_server_status "$STAT_PATH/$pid.stat" || exit 1
391 add_server_commands
392 return 0
393 }
394
395 # Process the -r flag.
396 process_r () {
397 local first_char="${1:1:1}"
398
399 if test "$first_char" = "/"; then # fully specified path
400 local kernel_build_tree="$1"
401 local version_file_name="$kernel_build_tree/include/config/kernel.release"
402 # The file include/config/kernel.release within the kernel
403 # build tree is used to pull out the version information
404 local kernel_release=`cat $version_file_name 2>/dev/null`
405 if test "X$kernel_release" = "X"; then
406 echo "Missing $version_file_name"
407 return 1
408 fi
409 SERVER_CMDS+=("RELEASE+=(\"`quote_for_cmd "$1"`\")") # pass the path as-is
410 return 0
411 fi
412
413 # kernel release specified directly
414 SERVER_CMDS+=("RELEASE+=(\"`quote_for_cmd "$1"`\")")
415 return 0
416 }
417
418 load_config () {
419 # Include configs
420 if [ -f "$CONFIG_FILE" ]; then
421 interpret_config_file "$CONFIG_FILE"
422 fi
423 if [ -f "$OPT_CONFIG_FILE" ]; then
424 interpret_config_file "$OPT_CONFIG_FILE"
425 fi
426 }
427
428 # Default to the currently running kernel release
429 get_release () {
430 $UNAME -r
431 }
432
433 # Default to the currently running kernel release
434 get_arch () {
435 stap_get_arch
436 }
437
438 add_server_commands () {
439 # Add commands based on the current state to SERVER_CMDS
440 SERVER_CMDS+=("ARCH=\"`quote_for_cmd "$ARCH"`\"")
441 SERVER_CMDS+=("RELEASE=()")
442 for r in "${RELEASE[@]}"; do
443 SERVER_CMDS+=("RELEASE+=(\"`quote_for_cmd "$r"`\")")
444 done
445 SERVER_CMDS+=("RUNTIME=\"`quote_for_cmd "$RUNTIME"`\"")
446 SERVER_CMDS+=("DEFINE=()")
447 for d in "${DEFINE[@]}"; do
448 SERVER_CMDS+=("DEFINE+=(\"`quote_for_cmd "$d"`\")")
449 done
450 SERVER_CMDS+=("INCLUDE=()")
451 for i in "${INCLUDE[@]}"; do
452 SERVER_CMDS+=("INCLUDE+=(\"`quote_for_cmd "$i"`\")")
453 done
454 SERVER_CMDS+=("BUILD=()")
455 for b in "${BUILD[@]}"; do
456 SERVER_CMDS+=("BUILD+=(\"`quote_for_cmd "$b"`\")")
457 done
458 SERVER_CMDS+=("USER=\"`quote_for_cmd "$USER"`\"")
459 SERVER_CMDS+=("NICKNAME=\"`quote_for_cmd "$NICKNAME"`\"")
460 SERVER_CMDS+=("LOG=\"`quote_for_cmd "$LOG"`\"")
461 test -n "$PORT" && SERVER_CMDS+=("PORT=\"`quote_for_cmd "$PORT"`\"")
462 test -n "$SSL" && SERVER_CMDS+=("SSL=\"`quote_for_cmd "$SSL"`\"")
463 test -n "$MAXTHREADS" && SERVER_CMDS+=("MAXTHREADS=\"`quote_for_cmd "$MAXTHREADS"`\"")
464 test -n "$MAXREQSIZE" && SERVER_CMDS+=("MAXREQSIZE=\"`quote_for_cmd "$MAXREQSIZE"`\"")
465 test -n "$MAXCOMPRESSEDREQ" && SERVER_CMDS+=("MAXCOMPRESSEDREQ=\"`quote_for_cmd "$MAXCOMPRESSEDREQ"`\"")
466 }
467
468 echo_server_options () {
469 # Echo the current state.
470 echo -n "-a \"`quote_for_cmd "$ARCH"`\""
471 for r in "${RELEASE[@]}"; do
472 echo -n " -r \"`quote_for_cmd "$r"`\""
473 done
474 test -n "$RUNTIME" && echo -n " -R \"`quote_for_cmd "$RUNTIME"`\""
475 for d in "${DEFINE[@]}"; do
476 echo -n " -D \"`quote_for_cmd "$d"`\""
477 done
478 for i in "${INCLUDE[@]}"; do
479 echo -n " -I \"`quote_for_cmd "$i"`\""
480 done
481 for b in "${BUILD[@]}"; do
482 echo -n " -B \"`quote_for_cmd "$b"`\""
483 done
484 echo -n " -u \"`quote_for_cmd "$USER"`\""
485 test -n "$NICKNAME" && echo -n " -n \"`quote_for_cmd "$NICKNAME"`\""
486 echo -n " --log \"`quote_for_cmd "$LOG"`\""
487 test -n "$PORT" && echo -n " --port \"`quote_for_cmd "$PORT"`\""
488 test -n "$SSL" && echo -n " --ssl \"`quote_for_cmd "$SSL"`\""
489 test -n "$MAXTHREADS" && echo -n " --max-threads \"`quote_for_cmd "$MAXTHREADS"`\""
490 test -n "$MAXREQSIZE" && echo -n " --max-request-size \"`quote_for_cmd "$MAXREQSIZE"`\""
491 test -n "$MAXCOMPRESSEDREQ" && echo -n " --max-compressed-request \"`quote_for_cmd "$MAXCOMPRESSEDREQ"`\""
492 echo
493 }
494
495 prepare_stat_dir () {
496 if [ ! -d "$STAT_PATH" ]; then
497 logex mkdir -p "$STAT_PATH"
498 [ $? -ne 0 ] && return 1
499 fi
500 return 0
501 }
502
503 prepare_certs () {
504 if [ "$USER" != "`id -un`" ]; then
505 if ! runuser -s /bin/bash - $USER -c 'test -f $HOME/.systemtap/ssl/server/stap.cert'; then
506 runuser -s /bin/bash - $USER -c ${PKGLIBEXECDIR}stap-gen-cert >/dev/null
507 fi
508 else
509 if ! test -f $HOME/.systemtap/ssl/server/stap.cert; then
510 ${PKGLIBEXECDIR}stap-gen-cert
511 fi
512 fi
513 }
514
515
516 prepare_log_dir () {
517 local log_path=`dirname "$1"`
518 if [ ! -d "$log_path" ]; then
519 mkdir -p "$log_path"
520 [ $? -ne 0 ] && return 1
521 fi
522 return 0
523 }
524
525 init_server_opts () {
526 ARCH=`get_arch`
527 unset RELEASE
528 unset DEFINE
529 unset BUILD
530 unset INCLUDE
531 NICKNAME=
532 NICKNAME_NOT_FOUND=
533 RUNTIME=
534 USER=$STAP_USER
535 test -z "$USER" && USER=`id -un`
536 LOG=$LOG_FILE
537 PORT=
538 SSL=
539 MAXTHREADS=
540 MAXREQSIZE=
541 MAXCOMPRESSEDREQ=
542 }
543
544 # Double quotes, backslashes within generated command
545 # arguments must be quoted.
546 quote_for_cmd () {
547 echo "$1" | \
548 sed -e 's/\\/\\\\/g' \
549 -e 's/"/\\"/g'
550 }
551
552 # Interpret the contents of a global config file.
553 interpret_config_file () {
554 local config_file="$1"
555
556 # Save the results locally first, in case there is an error.
557 local local_CONFIG_PATH=
558 local local_STAT_PATH=
559 local local_LOG_FILE=
560 local local_STAP_USER=
561
562 local input
563 while read -r -u3 input
564 do
565 case "$input" in
566 CONFIG_PATH=*)
567 local_CONFIG_PATH="${input:12}"
568 ;;
569 STAT_PATH=*)
570 local_STAT_PATH="${input:10}"
571 ;;
572 LOG_FILE=*)
573 local_LOG_FILE="${input:9}"
574 ;;
575 STAP_USER=*)
576 local_STAP_USER="${input:10}"
577 ;;
578 \#*)
579 ;; # Comment, do nothing
580 "")
581 ;; # Empty line, do nothing
582 *)
583 echo $"Invalid input, \"$input\", in $config_file" >&2
584 exit 1
585 ;;
586 esac
587 done 3< "$config_file"
588
589 # Now set the results globally
590 test -n "$local_CONFIG_PATH" && CONFIG_PATH="$local_CONFIG_PATH"
591 test -n "$local_STAT_PATH" && STAT_PATH="$local_STAT_PATH"
592 test -n "$local_LOG_FILE" && LOG_FILE="$local_LOG_FILE"
593 test -n "$local_STAP_USER" && STAP_USER="$local_STAP_USER"
594 }
595
596 # Interpret the contents of a server config file.
597 interpret_server_config () {
598 local config_file="$1"
599
600 # Save the results locally first, in case there is an error.
601 local local_ARCH=
602 local local_RELEASE=()
603 local local_DEFINE=()
604 local local_BUILD=()
605 local local_INCLUDE=()
606 local local_RUNTIME=
607 local local_USER=
608 local local_NICKNAME=
609 local local_LOG=
610 local local_PORT=
611 local local_SSL=
612 local local_MAXTHREADS=
613 local local_MAXREQSIZE=
614 local local_MAXCOMPRESSEDREQ=
615
616 local input
617 while read -r -u3 input
618 do
619 case "$input" in
620 ARCH=*)
621 local_ARCH="${input:5}"
622 ;;
623 RELEASE=*)
624 if [ -z "${input:8}" -o "${input:8}" = "()" ]; then
625 local_RELEASE=()
626 else
627 local_RELEASE=("${input:8}")
628 fi
629 ;;
630 RELEASE+=*)
631 test -z "${input:9}" -o "${input:9}" = "()" || \
632 local_RELEASE+=("${input:9}")
633 ;;
634 DEFINE=*)
635 if [ -z "${input:7}" -o "${input:7}" = "()" ]; then
636 local_DEFINE=()
637 else
638 local_DEFINE=("${input:7}")
639 fi
640 ;;
641 DEFINE+=*)
642 test -z "${input:8}" -o "${input:8}" = "()" || \
643 local_DEFINE+=("${input:8}")
644 ;;
645 BUILD=*)
646 if [ -z "${input:6}" -o "${input:6}" = "()" ]; then
647 local_BUILD=()
648 else
649 local_BUILD=("${input:6}")
650 fi
651 ;;
652 BUILD+=*)
653 test -z "${input:7}" -o "${input:7}" = "()" || \
654 local_BUILD+=("${input:7}")
655 ;;
656 INCLUDE=*)
657 if [ -z "${input:8}" -o "${input:8}" = "()" ]; then
658 local_INCLUDE=()
659 else
660 local_INCLUDE=("${input:8}")
661 fi
662 ;;
663 INCLUDE+=*)
664 test -z "${input:8}" -o "${input:8}" = "()" || \
665 local_INCLUDE+=("${input:9}")
666 ;;
667 RUNTIME=*)
668 local_RUNTIME="${input:8}"
669 ;;
670 USER=*)
671 local_USER="${input:5}"
672 ;;
673 NICKNAME=*)
674 local_NICKNAME="${input:9}"
675 ;;
676 LOG=*)
677 local_LOG="${input:4}"
678 ;;
679 PORT=*)
680 local_PORT="${input:5}"
681 ;;
682 SSL=*)
683 local_SSL="${input:4}"
684 ;;
685 MAXTHREADS=*)
686 local_MAXTHREADS="${input:11}"
687 ;;
688 MAXREQSIZE=*)
689 local_MAXREQSIZE="${input:11}"
690 ;;
691 MAXCOMPRESSEDREQ=*)
692 local_MAXCOMPRESSEDREQ="${input:17}"
693 ;;
694 \#*)
695 ;; # Comment, do nothing
696 "")
697 ;; # Empty line, do nothing
698 *)
699 echo $"Invalid input, \"$input\", in $config_file" >&2
700 exit 1
701 ;;
702 esac
703 done 3< "$config_file"
704
705 # Now set the results globally. All variables are expected to be set, even
706 # if to nothing.
707 ARCH="$local_ARCH"
708 RELEASE=("${local_RELEASE[@]}")
709 DEFINE=("${local_DEFINE[@]}")
710 BUILD=("${local_BUILD[@]}")
711 INCLUDE=("${local_INCLUDE[@]}")
712 RUNTIME="$local_RUNTIME"
713 USER="$local_USER"
714 NICKNAME="$local_NICKNAME"
715 LOG="$local_LOG"
716 PORT="$local_PORT"
717 SSL="$local_SSL"
718 MAXTHREADS="$local_MAXTHREADS"
719 MAXREQSIZE="$local_MAXREQSIZE"
720 MAXCOMPRESSEDREQ="$local_MAXCOMPRESSEDREQ"
721 }
722
723 # Interpret the contents of a server status file.
724 interpret_server_status () {
725 # The contents of the server status files are currently the same as
726 # that of server config files.
727 interpret_server_config "$1"
728 }
729
730 # Load the default server config and add the results to SERVER_CMDS.
731 load_server_config () {
732 for f in "$CONFIG_PATH"/*.conf; do
733 if [ -f "$f" ]; then
734 # Obtain a configuration from each config file.
735 # Ensure that we get the correct defaults for items not specified.
736 local ARCH=
737 local DEFINE=()
738 local BUILD=()
739 local INCLUDE=()
740 local RUNTIME=
741 local USER=
742 local RELEASE=()
743 local LOG=
744 local PORT=
745 local SSL=
746 local MAXTHREADS=
747 local MAXREQSIZE=
748 local MAXCOMPRESSEDREQ=
749 interpret_server_config "$f" || continue
750 # Other options default to empty. These ones don't.
751 [ -z "$ARCH" ] && ARCH=`get_arch`
752 [ -z "$RELEASE" ] && RELEASE+=(`get_release`)
753 [ -z "$USER" ] && USER=$STAP_USER
754 [ -z "$USER" ] && USER=`id -un`
755 [ -z "$LOG" ] && LOG="$LOG_FILE"
756 add_server_commands
757 SERVER_CMDS+=("EXEC")
758 fi
759 done
760 }
761
762 server_still_running () { # PID
763 (ps -e | grep stap-serverd | grep -q $1) && return 0 # Still running
764
765 rm -f "$STAT_PATH/$1.stat"
766 return 1 # Not running
767 }
768
769 get_server_pid_by_config () {
770 # Need to save the config, since the process of checking the running
771 # servers alters it.
772 local target_ARCH="$ARCH"
773 local target_RELEASE=("${RELEASE[@]}")
774 local target_RUNTIME="$RUNTIME"
775 local target_INCLUDE=("${INCLUDE[@]}")
776 local target_BUILD=("${BUILD[@]}")
777 local target_DEFINE=("${DEFINE[@]}")
778 local target_USER="$USER"
779 local target_NICKNAME="$NICKNAME"
780 local target_LOG="$LOG"
781 local target_PORT="$PORT"
782 local target_SSL="$SSL"
783 local target_MAXTHREADS="$MAXTHREADS"
784 local target_MAXREQSIZE="$MAXREQSIZE"
785 local target_MAXCOMPRESSEDREQ="$MAXCOMPRESSEDREQ"
786
787 # Check the status file for each running server to see if it matches
788 # the one currently configured. We're checking for a given configuration,
789 # so don't compare the nickname.
790 for f in "$STAT_PATH"/*.stat; do
791 test ! -e "$f" && continue
792 interpret_server_status "$f" || continue
793 test "X$ARCH" = "X$target_ARCH" || continue
794 test "X$RELEASE" = "X$target_RELEASE" || continue
795 test "X$INCLUDE" = "X$target_INCLUDE" || continue
796 test "X$RUNTIME" = "X$target_RUNTIME" || continue
797 test "X$BUILD" = "X$target_BUILD" || continue
798 test "X$DEFINE" = "X$target_DEFINE" || continue
799 test "X$USER" = "X$target_USER" || continue
800 test "X$LOG" = "X$target_LOG" || continue
801 test "X$PORT" = "X$target_PORT" || continue
802 test "X$SSL" = "X$target_SSL" || continue
803 test "X$MAXTHREADS" = "X$target_MAXTHREADS" || continue
804 test "X$MAXREQSIZE" = "X$target_MAXREQSIZE" || continue
805 test "X$MAXCOMPRESSEDREQ" = "X$target_MAXCOMPRESSEDREQ" || continue
806 echo `basename "$f" | sed 's/.stat//'` # Server has a pid
807 return
808 done
809
810 ARCH="$target_ARCH"
811 RELEASE=("${target_RELEASE[@]}")
812 RUNTIME="$target_RUNTIME"
813 INCLUDE=("${target_INCLUDE[@]}")
814 BUILD=("${target_BUILD[@]}")
815 DEFINE=("${target_DEFINE[@]}")
816 USER="$target_USER"
817 NICKNAME="$target_NICKNAME"
818 LOG="$target_LOG"
819 PORT="$target_PORT"
820 SSL="$target_SSL"
821 MAXTHREADS="$target_MAXTHREADS"
822 MAXREQSIZE="$target_MAXREQSIZE"
823 MAXCOMPRESSEDREQ="$target_MAXCOMPRESSEDREQ"
824 }
825
826 get_server_pid_by_nickname () {
827 # No need to save the current configuration. This function is not called
828 # in a context requiring it.
829 local target_NICKNAME="$1"
830
831 # Check the status file for each running server to see if the nickname
832 # matches the one we want.
833 for f in "$STAT_PATH"/*.stat; do
834 test ! -e "$f" && continue
835 interpret_server_status "$f" || continue
836 test "X$NICKNAME" = "X$target_NICKNAME" || continue
837 echo `basename "$f" | sed 's/\.stat//'` # Server with nickname was found
838 return
839 done
840 }
841
842 managed_servers () {
843 if [ ! -d "$STAT_PATH" ]; then
844 echo ""
845 return 1
846 fi
847 cd "$STAT_PATH"
848 local list=`ls | sed 's/\.stat//'`
849 if [ -z "$list" ]; then
850 echo ""
851 return 1
852 fi
853
854 echo "$list"
855 }
856
857 eval_server_command () {
858 local cmd="$1"
859 eval $cmd
860 }
861
862 start_server () {
863 clog $"Starting $prog `echo_server_options`"
864
865 # Is there already a server running for the requested kernel release
866 # and arch?
867 local server_pid=`get_server_pid_by_config`
868 if test -n "$server_pid"; then
869 if server_still_running $server_pid; then
870 do_success $"$prog start `echo_server_options`"
871 return 0 # Success
872 fi
873 fi
874
875 # Create certificates for this server
876 prepare_certs
877 if [ $? -ne 0 ]; then
878 echo $"Failed to make certificates ($USER .systemtap/ssl/server/stap.cert)" >&2
879 exit 1
880 fi
881
882 # Create the log directory for this server
883 prepare_log_dir "$LOG"
884 if [ $? -ne 0 ]; then
885 echo $"Failed to make log directory (`dirname "$LOG"`)" >&2
886 exit 1
887 fi
888
889 # Construct the server start command.
890 local server_cmd="$STAP_START_SERVER -a \"`quote_for_cmd "$ARCH"`\" $OPT_OTHER"
891 for r in "${RELEASE[@]}"; do
892 server_cmd="$server_cmd -r \"`quote_for_cmd "$r"`\""
893 done
894 for b in "${BUILD[@]}"; do
895 server_cmd="$server_cmd -B \"`quote_for_cmd "$b"`\""
896 done
897 for i in "${INCLUDE[@]}"; do
898 server_cmd="$server_cmd -I \"`quote_for_cmd "$i"`\""
899 done
900 for d in "${DEFINE[@]}"; do
901 server_cmd="$server_cmd -D \"`quote_for_cmd "$d"`\""
902 done
903 test -n "$RUNTIME" && server_cmd="$server_cmd -R \"`quote_for_cmd "$RUNTIME"`\""
904 server_cmd="$server_cmd --log=\"`quote_for_cmd "$LOG"`\""
905 test -n "$PORT" && server_cmd="$server_cmd --port \"`quote_for_cmd "$PORT"`\""
906 test -n "$SSL" && server_cmd="$server_cmd --ssl \"`quote_for_cmd "$SSL"`\""
907 test -n "$MAXTHREADS" && server_cmd="$server_cmd --max-threads \"`quote_for_cmd "$MAXTHREADS"`\""
908 test -n "$MAXREQSIZE" && server_cmd="$server_cmd --max-request-size \"`quote_for_cmd "$MAXREQSIZE"`\""
909 test -n "$MAXCOMPRESSEDREQ" && server_cmd="$server_cmd --max-compressed-request \"`quote_for_cmd "$MAXCOMPRESSEDREQ"`\""
910
911 # Start the server here.
912 local pid
913 if [ "$USER" != "`id -un`" ]; then
914 pid=`runuser -s /bin/bash - $USER -c "$server_cmd"`
915 else
916 pid=`eval $server_cmd`
917 fi
918 if [ $? != 0 -o -z "$pid" ]; then
919 if [ -n "$pid" ]; then
920 rm -f "$STAT_PATH/$pid.stat"
921 fi
922 do_failure $"$prog start `echo_server_options`"
923 return 1 # Failure
924 fi
925
926 # Nickname defaults to the pid.
927 test -z "$NICKNAME" && NICKNAME="$pid"
928
929 # Write the configuration to the status file.
930 local server_status_file="$STAT_PATH/$pid.stat"
931 echo "ARCH=$ARCH" > "$server_status_file"
932 echo "USER=$USER" >> "$server_status_file"
933 for b in "${BUILD[@]}"; do
934 echo "BUILD+=$b" >> "$server_status_file"
935 done
936 for i in "${INCLUDE[@]}"; do
937 echo "INCLUDE+=$i" >> "$server_status_file"
938 done
939 for d in "${DEFINE[@]}"; do
940 echo "DEFINE+=$d" >> "$server_status_file"
941 done
942 echo "NICKNAME=$NICKNAME" >> "$server_status_file"
943 echo "RUNTIME=$RUNTIME" >> "$server_status_file"
944 for r in "${RELEASE[@]}"; do
945 echo "RELEASE+=$r" >> "$server_status_file"
946 done
947 echo "LOG=$LOG" >> "$server_status_file"
948 echo "PORT=$PORT" >> "$server_status_file"
949 echo "SSL=$SSL" >> "$server_status_file"
950 echo "MAXTHREADS=$MAXTHREADS" >> "$server_status_file"
951 echo "MAXREQSIZE=$MAXREQSIZE" >> "$server_status_file"
952 echo "MAXCOMPRESSEDREQ=$MAXCOMPRESSEDREQ" >> "$server_status_file"
953
954 do_success $"$prog start `echo_server_options`"
955 }
956
957 start () { # server-cmds
958 prepare_stat_dir
959 if [ $? -ne 0 ]; then
960 do_failure $"Failed to make stat directory ($STAT_PATH)"
961 return 1
962 fi
963
964 # Start the specified servers
965 local server_cmds=("$@")
966
967 # If none specified, start the configured servers
968 if [ -z "$server_cmds" ]; then
969 unset SERVER_CMDS
970 load_server_config
971 server_cmds=("${SERVER_CMDS[@]}")
972 # If none configured, start the default servers
973 if test -z "$server_cmds"; then
974 add_distributed_options
975 server_cmds=("${SERVER_CMDS[@]}")
976 server_cmds+=("EXEC")
977 fi
978 fi
979
980 # Start each requested server in turn
981 local rc=0
982 local first=1
983 init_server_opts
984 local cmd
985 local prevCmd
986 for cmd in "${server_cmds[@]}"; do
987 prevCmd="$cmd"
988 # Evaluate commands until the EXEC command is found.
989 if test "$cmd" != "EXEC"; then
990 eval_server_command "$cmd"
991 # A specified nickname only sticks if it is the final command.
992 # Otherwise, we have a configuration based on a nicknamed
993 # configuration.
994 echo "$cmd" | grep -q "^NICKNAME=" || NICKNAME=""
995 continue
996 fi
997 # If a nickname was specified, but the corresponding config was not found,
998 # then it is the nickname for this new configuration.
999 if test -n "$NICKNAME_NOT_FOUND"; then
1000 NICKNAME="$NICKNAME_NOT_FOUND"
1001 NICKNAME_NOT_FOUND=
1002 fi
1003
1004 # Start the configured server
1005 test $first = 0 && echo
1006 first=0
1007 start_server || rc=1
1008
1009 # Don't use the same nickname for the next server.
1010 NICKNAME=
1011 done
1012
1013 return $rc
1014 }
1015
1016 stop () { # server-cmds
1017 local first=1
1018 local server_list=
1019 local server_cmds=("$@")
1020 if [ -n "$server_cmds" ]; then
1021 # Get the pids of all the requested servers.
1022 init_server_opts
1023 local cmd
1024 local prevCmd
1025 for cmd in "${server_cmds[@]}"; do
1026 prevCmd="$cmd"
1027 # Evaluate commands until the EXEC command is found.
1028 if test "$cmd" != "EXEC"; then
1029 eval_server_command "$cmd"
1030 # A specified nickname only sticks if it is the final command.
1031 # Otherwise, we have a configuration based on a nicknamed
1032 # configuration.
1033 echo "$cmd" | grep -q "^NICKNAME=" || NICKNAME=""
1034 continue
1035 fi
1036 # If a nickname was specified, but the corresponding config was not
1037 # found, it is an error.
1038 if test -n "$NICKNAME_NOT_FOUND"; then
1039 clog "No configuration found for the nickname '$NICKNAME_NOT_FOUND'"
1040 NICKNAME="$NICKNAME_NOT_FOUND"
1041 do_failure $"$prog stop `echo_server_options`"
1042 NICKNAME_NOT_FOUND=
1043 rc=1
1044 continue
1045 fi
1046
1047 # Get the pid for this server, if it's running
1048 local server_pid=`get_server_pid_by_config`
1049 if test -n "$server_pid"; then
1050 server_list="$server_list $server_pid"
1051 continue
1052 fi
1053
1054 # This server is not running, but give a success stop status anyway.
1055 test $first = 0 && echo
1056 first=0
1057 clog $"Stopping $prog `echo_server_options`"
1058 do_success $"$prog stop `echo_server_options`"
1059 done
1060 else
1061 server_list=`managed_servers`
1062 if [ -z "$server_list" ]; then
1063 clog $"Stopping $prog: " -n
1064 do_success $"$prog: No managed servers to stop"
1065 return 0
1066 fi
1067 fi
1068
1069 # Stop each server in turn
1070 local rc=0
1071 local pid
1072 for pid in $server_list; do
1073 if ! interpret_server_status "$STAT_PATH/$pid.stat"; then
1074 rc=1
1075 continue
1076 fi
1077
1078 test $first = 0 && echo
1079 first=0
1080 clog $"Stopping $prog `echo_server_options`"
1081
1082 local this_rc=0
1083 if server_still_running $pid; then
1084 if [ "$USER" != "`id -un`" ]; then
1085 runuser -s /bin/bash - $USER -c "$STAP_STOP_SERVER $pid"
1086 else
1087 eval $STAP_STOP_SERVER $pid
1088 fi
1089 if [ $? != 0 ]; then
1090 do_failure $"$prog stop `echo_server_options`"
1091 this_rc=1
1092 rc=1
1093 fi
1094 fi
1095 if [ $this_rc = 0 ]; then
1096 rm -f "$STAT_PATH/$pid.stat"
1097 do_success $"$prog stop `echo_server_options`"
1098 fi
1099 done
1100
1101 return $rc
1102 }
1103
1104 status () { # server-list
1105 local rc=0
1106
1107 # Report status for the specified servers or all running servers, if none
1108 # specified.
1109 local server_list=
1110 local server_cmds=("$@")
1111 if [ -n "$server_cmds" ]; then
1112 # Get the pids of all the requested servers.
1113 init_server_opts
1114 local cmd
1115 local prevCmd
1116 for cmd in "${server_cmds[@]}"; do
1117 prevCmd="$cmd"
1118 # Evaluate commands until the EXEC command is found.
1119 if test "$cmd" != "EXEC"; then
1120 eval_server_command "$cmd"
1121 # A specified nickname only sticks if it is the final command.
1122 # Otherwise, we have a configuration based on a nicknamed
1123 # configuration.
1124 echo "$cmd" | grep -q "^NICKNAME=" || NICKNAME=""
1125 continue
1126 fi
1127 # If a nickname was specified, but the corresponding config was not
1128 # found, say so.
1129 if test -n "$NICKNAME_NOT_FOUND"; then
1130 echo "No configuration found for the nickname '$NICKNAME_NOT_FOUND'"
1131 NICKNAME_NOT_FOUND=
1132 rc=3
1133 continue
1134 fi
1135
1136 # Get the pid for this server, if it's running
1137 local server_pid=`get_server_pid_by_config`
1138 if test -n "$server_pid"; then
1139 server_list="$server_list $server_pid"
1140 continue
1141 fi
1142 # This server is not running
1143 echo "stap-server `echo_server_options` is not running"
1144 rc=3
1145 done
1146 else
1147 server_list=`managed_servers`
1148 if [ -z "$server_list" ]; then
1149 echo "No managed stap-server is running"
1150 return 3
1151 fi
1152 fi
1153
1154 # Get status of each server in turn
1155 local pid
1156 for pid in $server_list; do
1157 if ! interpret_server_status "$STAT_PATH/$pid.stat"; then
1158 rc=1
1159 continue
1160 fi
1161 if ! server_still_running $pid; then
1162 echo "stap-server `echo_server_options` started as PID $pid is no longer running"
1163 rc=1
1164 continue
1165 fi
1166 echo "stap-server `echo_server_options` running as PID $pid"
1167 done
1168
1169 return $rc
1170 }
1171
1172 # Restart or start if not running
1173 function restart () { # server-cmds
1174 # Restart the specified servers or all servers, if none specified.
1175 local rc=0
1176 local server_cmds=("$@")
1177 if [ -z "$server_cmds" ]; then
1178 local server_list=`managed_servers`
1179 local pid
1180 for pid in $server_list; do
1181 if ! interpret_server_status "$STAT_PATH/$pid.stat"; then
1182 rc=1
1183 continue
1184 fi
1185 unset SERVER_CMDS
1186 add_server_commands
1187 server_cmds+=("${SERVER_CMDS[@]}")
1188 server_cmds+=("EXEC")
1189 done
1190 fi
1191
1192 # Stop the specified servers, or all if none specified
1193 stop "${server_cmds[@]}" || rc=1
1194 echo
1195
1196 # Restart the same servers. If none were specified then
1197 # start the configured or default server(s)).
1198 start "${server_cmds[@]}"
1199 local this_rc=$?
1200 [ $this_rc != 0 ] && rc=$this_rc
1201
1202 return $rc
1203 }
1204
1205 # Restart only if running
1206 function condrestart () { # server-list
1207 # Restart the specified servers or all servers, if none specified,
1208 # but only if they are already running.
1209 local rc=0
1210 local server_cmds=("$@")
1211 if [ -z "$server_cmds" ]; then
1212 local server_list=`managed_servers`
1213 local pid
1214 for pid in $server_list; do
1215 if ! interpret_server_status "$STAT_PATH/$pid.stat"; then
1216 rc=1
1217 continue
1218 fi
1219 unset SERVER_CMDS
1220 add_server_commands
1221 server_cmds+=("${SERVER_CMDS[@]}")
1222 server_cmds+=("EXEC")
1223 done
1224 # No server specified or running?
1225 if [ -z "$server_cmds" ]; then
1226 clog "No managed stap-server is running" -n
1227 do_success "No managed stap-server is running"
1228 return 0
1229 fi
1230 fi
1231
1232 # For each server in the list, stop it if it is running
1233 local first=1
1234 local this_server_cmds
1235 local cmd
1236 for cmd in "${server_cmds[@]}"; do
1237 # Execute and collect commands until the EXEC command is found.
1238 this_server_cmds+=("$cmd")
1239 if test "$cmd" != "EXEC"; then
1240 eval_server_command "$cmd"
1241 continue
1242 fi
1243
1244 test $first = 0 && echo
1245 first=0
1246
1247 # Now see if this server is running
1248 if ! status "${this_server_cmds[@]}" >/dev/null 2>&1; then
1249 clog $"$prog `echo_server_options` is not running"
1250 do_success "$prog `echo_server_options` is not running"
1251 unset this_server_cmds
1252 continue
1253 fi
1254
1255 start_cmds+=("${this_server_cmds[@]}")
1256
1257 stop "${this_server_cmds[@]}"
1258 this_rc=$?
1259 [ $this_rc != 0 ] && rc=$this_rc
1260
1261 unset this_server_cmds
1262 done
1263
1264 # Now restart the servers that were running
1265 if [ -n "$start_cmds" ]; then
1266 echo
1267 start "${start_cmds[@]}"
1268 local this_rc=$?
1269 [ $this_rc != 0 ] && rc=$this_rc
1270 fi
1271
1272 return $rc
1273 }
1274
1275 #------------------------------------------------------------------
1276 # Mainline script
1277 #------------------------------------------------------------------
1278 CMD=$1
1279 shift 1
1280
1281 prepare_log_dir "$LOG_FILE"
1282 if [ $? -ne 0 ]; then
1283 echo $"Failed to make log directory (`dirname $LOG_FILE`)" >&2
1284 exit 1
1285 fi
1286
1287 OPTS=`getopt -s bash -u --options 'a:B:c:D:iI:n:p:kPr:R:u:' \
1288 --longoptions 'log:' \
1289 --longoptions 'port:' \
1290 --longoptions 'ssl:' \
1291 --longoptions 'max-threads:' \
1292 --longoptions 'max-request-size:' \
1293 --longoptions 'max-compressed-request:' \
1294 -- "$@"`
1295 if [ $? -ne 0 ]; then
1296 echo "Error: Argument parse error: $@" >&2
1297 echo_usage
1298 exit 2
1299 fi
1300
1301 # Initialize server specs
1302 parse_args "$@" || exit 2
1303 load_config
1304
1305 RETVAL=0
1306
1307 case $CMD in
1308 start) # Start specified servers. If none specified, start configured servers
1309 start "${SERVER_CMDS[@]}"
1310 RETVAL=$?
1311 ;;
1312 stop) # Stop specified servers
1313 stop "${SERVER_CMDS[@]}"
1314 RETVAL=$?
1315 ;;
1316 restart) # Restart specified servers
1317 restart "${SERVER_CMDS[@]}"
1318 RETVAL=$?
1319 ;;
1320 condrestart|try-restart) # Restart specified servers if they are running
1321 condrestart "${SERVER_CMDS[@]}"
1322 RETVAL=$?
1323 ;;
1324 status) # Give status on specified servers
1325 status "${SERVER_CMDS[@]}"
1326 exit $?
1327 ;;
1328 reload) # Reloading config without stop/restart is not supported
1329 RETVAL=3
1330 ;;
1331 force-reload) # Reload config with stop/start
1332 # stop all running servers
1333 stop
1334 echo
1335 # Restart specified servers
1336 # If none specified, restart configured servers
1337 start "${SERVER_CMDS[@]}"
1338 RETVAL=$?
1339 ;;
1340 usage|*)
1341 echo_usage
1342 RETVAL=0
1343 ;;
1344 esac
1345
1346 echo
1347 exit $RETVAL