3 # stap-server script for managing the systemtap compile server
5 # Copyright (C) 2008-2011 Red Hat Inc.
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
12 # This script provides management of systemtap compile servers as a service.
13 # See stap-server(8) for more information.
15 if [ -f /etc
/rc.d
/init.d
/functions
]; then
16 # Red Hat init functions
17 .
/etc
/rc.d
/init.d
/functions
19 # Default init functions
28 # Systemtap function library
29 .
${PKGLIBEXECDIR}stap-env
34 STAP_START_SERVER
=${stap_pkglibexecdir}stap-start-server
35 STAP_STOP_SERVER
=${stap_pkglibexecdir}stap-stop-server
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
44 # Default option settings
45 # Optional global config file
55 echo $
"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|status} [options]"
57 echo $
" -c configfile : specify additional global configuration file."
58 echo $
" -a arch : specify the target architecture."
59 echo $
" -r release : specify the kernel release."
60 echo $
" -I path : augment the search path for tapsets."
61 echo $
" -R path : specify the location of the systemtap runtime."
62 echo $
" -B options : specify 'make' options for building systemtap modules."
63 echo $
" -D name[=value] : add a macro definition for building systemtap modules."
64 echo $
" -u username : specify the user who will run the server(s)."
65 echo $
" -i : specify a server for each installed kernel release."
66 echo $
" -n nickname : specify a server configuration by nickname."
67 echo $
" -p pid : specify a server or server configuration by process id."
68 echo $
" -P : use a password for the server's NSS certificate database."
69 echo $
" -k : keep server temporary files."
70 echo $
" --port port : specify the network port to be used by the server."
71 echo $
" --log path : specify the location of the server's log file."
72 echo $
" --ssl path : specify the location of the server's certificate database."
73 echo $
" --max-threads threads : specify the maximum number of worker threads to handle concurrent requests."
75 echo $
"All options may be specified more than once."
77 echo $
"If -a is not specified, the default architecture is that of the host"
80 echo $
"If -r is not specified, the default kernel release is that currently"
81 echo $
"running on the host platform."
83 echo $
"If -u is not specified, the default user is 'stap-server'"
85 echo $
"If --port is not specified, the default is to use a randomly selected port."
87 echo $
"If --log is not specified, the default is '$stap_localstatedir/log/stap-server/log'."
89 echo $
"If --ssl is not specified, the default is '$stap_sysconfdir/ssl/server'."
91 echo $
"If --max-threads is not specified, the default is the number of processors."
93 echo $
"If --max-threads is specified with a value of 0, all requests are handled in the main thread."
95 echo $
"Each -D, -I and -B option specifies an additional macro, path or option respectively"
96 echo $
"to be applied to subsequent servers specified."
98 echo $
"Each --port, --log, --ssl and --max-threads option is added to an option-specific list"
99 echo $
"which will be applied, in turn, to each server specified. If more servers are specified"
100 echo $
"than options in a given list, the default for that option will be used for subsequent"
103 echo $
"For other options, each new instance overrides the previous setting."
105 echo $
"The -i option is a shortcut which specifies one server for each kernel"
106 echo $
"release installed in /lib/modules/. Previous -D, -I, -R, -B and -u"
107 echo $
"options will be applied to each server, however previous -a options"
108 echo $
"are ignored and the default architecture is used."
110 echo $
"The -n option allows the specification of a server configuration by"
111 echo $
"nickname. When -n is specified, a currently running server with the"
112 echo $
"given nickname will be searched for. If no currently running server"
113 echo $
"with the given nickname is found, a server configuration with the"
114 echo $
"given nickname will be searched for in"
115 echo $
"$stap_sysconfdir/stap-server/conf.d/*.conf."
116 echo $
"If a server configuration for the given nickname is found, the -a, -r,"
117 echo $
"-D, -I, -R, -B and -u options for that server will be used as if they were"
118 echo $
"specified on the command line. If no configuration with the given"
119 echo $
"nickname is found, and the action is 'start' (or an action behaving"
120 echo $
"like 'start' (see below)), the server will be started with the given"
121 echo $
"nickname. If no configuration with the given nickname is found, and"
122 echo $
"the action is not 'start' (or an action behaving" "like 'start',"
123 echo $
"it is an error. If a nickname is not specified for a server, its"
124 echo $
"nickname will be its process id."
126 echo $
"The -p option allows the specification of a server configuration by"
127 echo $
"process id. When -p is specified, a currently running server with the"
128 echo $
"given process id will be searched for. If no such server is found,"
129 echo $
"it is an error. If a server with the given pid is found, the -a, -r,"
130 echo $
"-D, -I, -R, -B and -u options for that server will be used as if they were"
131 echo $
"specified on the command line."
133 echo $
"The -k option tells the server to keep the temporary directories it creates"
134 echo $
"during each transaction with a client."
136 echo $
"The specified action is performed for the server(s) specified on the"
137 echo $
"command line. If no servers are specified on the command line, the"
138 echo $
"behavior is as follows:"
140 echo $
" start: Start the servers configured in $stap_sysconfdir/stap-server/conf.d/*.conf."
141 echo $
" If none are configured, start a server for the kernel release"
142 echo $
" and architecture of the host platform."
144 echo $
" stop: Stop all currently running servers."
146 echo $
" restart: Restart all currently running servers. If no servers are running,"
147 echo $
" behave as if 'start' was specified."
149 echo $
" condrestart: Restart all currently running servers. If no servers are running,"
152 echo $
" try-restart: Same as condrestart."
154 echo $
" force-reload: Stop all currently running servers and behave as if 'start'"
155 echo $
" was specified."
157 echo $
" status: Report the status of all current running servers."
161 #-----------------------------------------------------------------
163 #-----------------------------------------------------------------
165 echo `LC_ALL=en date +"%b %e %T"`": $1" >> "$LOG_FILE"
167 clog
() { # message [-n]
172 logger
"$1" # if syslogd is running, this message will be sent to syslog.
176 eval log
\"Exec
: "$@"\"
177 "$@" >> "$LOG_FILE" 2>&1
180 do_failure
() { # message
184 do_success
() { # message
189 #------------------------------------------------------------------
190 # Parameter parsing and setup options
191 #------------------------------------------------------------------
192 parse_args
() { # arguments
195 while [ -n "$1" ]; do
198 OPT_OTHER
="$OPT_OTHER $1"
203 SERVER_CMDS
+=("ARCH=\"`quote_for_cmd "$2"`\"")
208 SERVER_CMDS
+=("BUILD+=(\"`quote_for_cmd "$2"`\")")
216 # Delay processing of -i in case a distributed option like --log is specified which could
217 # apply to each server referenced by -i. We will process it just before handling other
218 # options which describe a new server (e.g. -r).
219 i_specified
=$
(($i_specified + 1))
223 SERVER_CMDS
+=("DEFINE+=(\"`quote_for_cmd "$2"`\")")
228 SERVER_CMDS
+=("INCLUDE+=(\"`quote_for_cmd "$2"`\")")
250 SERVER_CMDS
+=("RUNTIME=\"`quote_for_cmd "$2"`\"")
255 SERVER_CMDS
+=("USER=\"`quote_for_cmd "$2"`\"")
271 OPT_MAXTHREADS
+=("$2")
283 # Process any lingering -i
286 # Add options from any lists and an EXEC command to the end if any server options were specified
287 if test -n "$SERVER_CMDS"; then
288 add_distributed_options
289 SERVER_CMDS
+=("EXEC")
292 test $rc != 0 && echo_usage
296 # Some options accumulate into lists when specified more than once. The items in the each list
297 # are the applied to each specified server in turn. If a list runs out, then the default for that
299 add_distributed_options
() {
301 if test -n "${OPT_LOG[$OPT_LOG_IX]}"; then
302 SERVER_CMDS
+=("LOG=\"`quote_for_cmd "${OPT_LOG[$OPT_LOG_IX]}"`\"")
303 OPT_LOG_IX
=$
(($OPT_LOG_IX + 1))
305 SERVER_CMDS
+=("LOG=\"`quote_for_cmd "$LOG_FILE"`\"")
308 if test -n "${OPT_PORT[$OPT_PORT_IX]}"; then
309 SERVER_CMDS
+=("PORT=\"`quote_for_cmd "${OPT_PORT[$OPT_PORT_IX]}"`\"")
310 OPT_PORT_IX
=$
(($OPT_PORT_IX + 1))
312 SERVER_CMDS
+=("PORT=\"\"")
315 if test -n "${OPT_SSL[$OPT_SSL_IX]}"; then
316 SERVER_CMDS
+=("SSL=\"`quote_for_cmd "${OPT_SSL[$OPT_SSL_IX]}"`\"")
317 OPT_SSL_IX
=$
(($OPT_SSL_IX + 1))
319 SERVER_CMDS
+=("SSL=\"\"")
321 # The --max-threads option
322 if test -n "${OPT_MAXTHREADS[$OPT_MAXTHREADS_IX]}"; then
323 SERVER_CMDS
+=("MAXTHREADS=\"`quote_for_cmd "${OPT_MAXTHREADS[$OPT_MAXTHREADS_IX]}"`\"")
324 OPT_MAXTHREADS_IX
=$
(($OPT_MAXTHREADS_IX + 1))
326 SERVER_CMDS
+=("MAXTHREADS=\"\"")
330 # Process the -i flag.
334 while test $i_specified -gt 0; do
335 for release
in `ls`; do
336 if test -n "$SERVER_CMDS"; then
337 add_distributed_options
338 SERVER_CMDS
+=("EXEC")
342 i_specified
=$
(($i_specified - 1))
348 # Process the -n flag.
350 local target_NICKNAME
="$1"
352 # Is there a running server with this nickname?
353 local pid
=`get_server_pid_by_nickname "$target_NICKNAME"`
354 if [ -n "$pid" ]; then
355 # Read the configuration and add it to the configuration commands.
356 interpret_server_status
"$STAT_PATH/$pid.stat" ||
continue
361 # Is there a server configuration with this nickname?
362 for f
in "$CONFIG_PATH"/*.conf
; do
364 interpret_server_config
"$f" ||
continue
365 test "X$NICKNAME" = "X$target_NICKNAME" ||
continue
371 # No server configuration could be found for this nickname. Add a
372 # NICKNAME_NOT_FOUND=... command to the configuration commands.
373 SERVER_CMDS
+=("NICKNAME_NOT_FOUND=\"`quote_for_cmd "$target_NICKNAME"`\"")
376 # Process the -p flag.
380 # Are we managing a server with the given pid?
381 test ! -f "$STAT_PATH/$pid.stat" && echo "No stap-server running as pid $pid" && \
384 # Add the configuration of the server running as $pid to SERVER_CMDS
385 interpret_server_status
"$STAT_PATH/$pid.stat" ||
exit 1
390 # Process the -r flag.
392 local first_char
="${1:1:1}"
394 if test "$first_char" = "/"; then # fully specified path
395 local kernel_build_tree
="$1"
396 local version_file_name
="$kernel_build_tree/include/config/kernel.release"
397 # The file include/config/kernel.release within the kernel
398 # build tree is used to pull out the version information
399 local kernel_release
=`cat $version_file_name 2>/dev/null`
400 if test "X$kernel_release" = "X"; then
401 echo "Missing $version_file_name"
404 SERVER_CMDS
+=("RELEASE=\"`quote_for_cmd "$1"`\"") # pass the path as-is
408 # kernel release specified directly
409 SERVER_CMDS
+=("RELEASE=\"`quote_for_cmd "$1"`\"")
415 if [ -f "$CONFIG_FILE" ]; then
416 interpret_config_file
"$CONFIG_FILE"
418 if [ -f "$OPT_CONFIG_FILE" ]; then
419 interpret_config_file
"$OPT_CONFIG_FILE"
423 # Default to the currently running kernel release
428 # Default to the currently running kernel release
433 add_server_commands
() {
434 # Add commands based on the current state to SERVER_CMDS
435 SERVER_CMDS
+=("ARCH=\"`quote_for_cmd "$ARCH"`\"")
436 SERVER_CMDS
+=("RELEASE=\"`quote_for_cmd "$RELEASE"`\"")
437 SERVER_CMDS
+=("RUNTIME=\"`quote_for_cmd "$RUNTIME"`\"")
438 SERVER_CMDS
+=("DEFINE=()")
439 for d
in "${DEFINE[@]}"; do
440 SERVER_CMDS
+=("DEFINE+=(\"`quote_for_cmd "$d"`\")")
442 SERVER_CMDS
+=("INCLUDE=()")
443 for i
in "${INCLUDE[@]}"; do
444 SERVER_CMDS
+=("INCLUDE+=(\"`quote_for_cmd "$i"`\")")
446 SERVER_CMDS
+=("BUILD=()")
447 for b
in "${BUILD[@]}"; do
448 SERVER_CMDS
+=("BUILD+=(\"`quote_for_cmd "$b"`\")")
450 SERVER_CMDS
+=("USER=\"`quote_for_cmd "$USER"`\"")
451 SERVER_CMDS
+=("NICKNAME=\"`quote_for_cmd "$NICKNAME"`\"")
452 SERVER_CMDS
+=("LOG=\"`quote_for_cmd "$LOG"`\"")
453 test -n "$PORT" && SERVER_CMDS
+=("PORT=\"`quote_for_cmd "$PORT"`\"")
454 test -n "$SSL" && SERVER_CMDS
+=("SSL=\"`quote_for_cmd "$SSL"`\"")
455 test -n "$MAXTHREADS" && SERVER_CMDS
+=("MAXTHREADS=\"`quote_for_cmd "$MAXTHREADS"`\"")
458 echo_server_options
() {
459 # Echo the current state.
460 echo -n "-a \"`quote_for_cmd "$ARCH"`\""
461 echo -n " -r \"`quote_for_cmd "$RELEASE"`\""
462 test -n "$RUNTIME" && echo -n " -R \"`quote_for_cmd "$RUNTIME"`\""
463 for d
in "${DEFINE[@]}"; do
464 echo -n " -D \"`quote_for_cmd "$d"`\""
466 for i
in "${INCLUDE[@]}"; do
467 echo -n " -I \"`quote_for_cmd "$i"`\""
469 for b
in "${BUILD[@]}"; do
470 echo -n " -B \"`quote_for_cmd "$b"`\""
472 echo -n " -u \"`quote_for_cmd "$USER"`\""
473 test -n "$NICKNAME" && echo -n " -n \"`quote_for_cmd "$NICKNAME"`\""
474 echo -n " --log \"`quote_for_cmd "$LOG"`\""
475 test -n "$PORT" && echo -n " --port \"`quote_for_cmd "$PORT"`\""
476 test -n "$SSL" && echo -n " --ssl \"`quote_for_cmd "$SSL"`\""
477 test -n "$MAXTHREADS" && echo -n " --max-threads \"`quote_for_cmd "$MAXTHREADS"`\""
481 prepare_stat_dir
() {
482 if [ ! -d "$STAT_PATH" ]; then
483 logex mkdir
-p "$STAT_PATH"
484 [ $?
-ne 0 ] && return 1
490 local log_path
=`dirname "$1"`
491 if [ ! -d "$log_path" ]; then
493 [ $?
-ne 0 ] && return 1
498 init_server_opts
() {
500 RELEASE
=`get_release`
508 test -z "$USER" && USER
=`id -un`
515 # Double quotes, backslashes within generated command
516 # arguments must be quoted.
519 sed -e 's/\\/\\\\/g' \
523 # Interpret the contents of a global config file.
524 interpret_config_file
() {
525 local config_file
="$1"
527 # Save the results locally first, in case there is an error.
528 local local_CONFIG_PATH
=
529 local local_STAT_PATH
=
530 local local_LOG_FILE
=
531 local local_STAP_USER
=
534 while read -r -u3 input
538 local_CONFIG_PATH
="${input:12}"
541 local_STAT_PATH
="${input:10}"
544 local_LOG_FILE
="${input:9}"
547 local_STAP_USER
="${input:10}"
550 ;; # Comment, do nothing
552 ;; # Empty line, do nothing
554 echo $
"Invalid input, \"$input\", in $config_file" >&2
558 done 3< "$config_file"
560 # Now set the results globally
561 test -n "$local_CONFIG_PATH" && CONFIG_PATH
="$local_CONFIG_PATH"
562 test -n "$local_STAT_PATH" && STAT_PATH
="$local_STAT_PATH"
563 test -n "$local_LOG_FILE" && LOG_FILE
="$local_LOG_FILE"
564 test -n "$local_STAP_USER" && STAP_USER
="$local_STAP_USER"
567 # Interpret the contents of a server config file.
568 interpret_server_config
() {
569 local config_file
="$1"
571 # Save the results locally first, in case there is an error.
574 local local_DEFINE
=()
576 local local_INCLUDE
=()
579 local local_NICKNAME
=
583 local local_MAXTHREADS
=
586 while read -r -u3 input
590 local_ARCH
="${input:5}"
593 local_RELEASE
="${input:8}"
596 if [ -z "${input:7}" -o "${input:7}" = "()" ]; then
599 local_DEFINE
=("${input:7}")
603 test -z "${input:8}" -o "${input:8}" = "()" || \
604 local_DEFINE
+=("${input:8}")
607 if [ -z "${input:6}" -o "${input:6}" = "()" ]; then
610 local_BUILD
=("${input:6}")
614 test -z "${input:7}" -o "${input:7}" = "()" || \
615 local_BUILD
+=("${input:7}")
618 if [ -z "${input:8}" -o "${input:8}" = "()" ]; then
621 local_INCLUDE
=("${input:8}")
625 test -z "${input:8}" -o "${input:8}" = "()" || \
626 local_INCLUDE
+=("${input:9}")
629 local_RUNTIME
="${input:8}"
632 local_USER
="${input:5}"
635 local_NICKNAME
="${input:9}"
638 local_LOG
="${input:4}"
641 local_PORT
="${input:5}"
644 local_SSL
="${input:4}"
647 local_MAXTHREADS
="${input:11}"
650 ;; # Comment, do nothing
652 ;; # Empty line, do nothing
654 echo $
"Invalid input, \"$input\", in $config_file" >&2
658 done 3< "$config_file"
660 # Now set the results globally. All variables are expected to be set, even
663 RELEASE
="$local_RELEASE"
664 DEFINE
=("${local_DEFINE[@]}")
665 BUILD
=("${local_BUILD[@]}")
666 INCLUDE
=("${local_INCLUDE[@]}")
667 RUNTIME
="$local_RUNTIME"
669 NICKNAME
="$local_NICKNAME"
673 MAXTHREADS
="$local_MAXTHREADS"
676 # Interpret the contents of a server status file.
677 interpret_server_status
() {
678 # The contents of the server status files are currently the same as
679 # that of server config files.
680 interpret_server_config
"$1"
683 # Load the default server config and add the results to SERVER_CMDS.
684 load_server_config
() {
685 for f
in "$CONFIG_PATH"/*.conf
; do
687 # Obtain a configuration from each config file.
688 # Ensure that we get the correct defaults for items not specified.
700 interpret_server_config
"$f" ||
continue
701 # Other options default to empty. These ones don't.
702 [ -z "$ARCH" ] && ARCH
=`get_arch`
703 [ -z "$RELEASE" ] && RELEASE
=`get_release`
704 [ -z "$USER" ] && USER
=$STAP_USER
705 [ -z "$USER" ] && USER
=`id -un`
706 [ -z "$LOG" ] && LOG
="$LOG_FILE"
708 SERVER_CMDS
+=("EXEC")
713 server_still_running
() { # PID
714 (ps
-e |
grep stap-serverd |
grep -q $1) && return 0 # Still running
716 rm -f "$STAT_PATH/$1.stat"
717 return 1 # Not running
720 get_server_pid_by_config
() {
721 # Need to save the config, since the process of checking the running
723 local target_ARCH
="$ARCH"
724 local target_RELEASE
="$RELEASE"
725 local target_RUNTIME
="$RUNTIME"
726 local target_INCLUDE
=("${INCLUDE[@]}")
727 local target_BUILD
=("${BUILD[@]}")
728 local target_DEFINE
=("${DEFINE[@]}")
729 local target_USER
="$USER"
730 local target_NICKNAME
="$NICKNAME"
731 local target_LOG
="$LOG"
732 local target_PORT
="$PORT"
733 local target_SSL
="$SSL"
734 local target_MAXTHREADS
="$MAXTHREADS"
736 # Check the status file for each running server to see if it matches
737 # the one currently configured. We're checking for a given configuration,
738 # so don't compare the nickname.
739 for f
in "$STAT_PATH"/*.stat
; do
740 test ! -e "$f" && continue
741 interpret_server_status
"$f" ||
continue
742 test "X$ARCH" = "X$target_ARCH" ||
continue
743 test "X$RELEASE" = "X$target_RELEASE" ||
continue
744 test "X$INCLUDE" = "X$target_INCLUDE" ||
continue
745 test "X$RUNTIME" = "X$target_RUNTIME" ||
continue
746 test "X$BUILD" = "X$target_BUILD" ||
continue
747 test "X$DEFINE" = "X$target_DEFINE" ||
continue
748 test "X$USER" = "X$target_USER" ||
continue
749 test "X$LOG" = "X$target_LOG" ||
continue
750 test "X$PORT" = "X$target_PORT" ||
continue
751 test "X$SSL" = "X$target_SSL" ||
continue
752 test "X$MAXTHREADS" = "X$target_MAXTHREADS" ||
continue
753 echo `basename "$f" | sed 's/.stat//'` # Server has a pid
758 RELEASE
="$target_RELEASE"
759 RUNTIME
="$target_RUNTIME"
760 INCLUDE
=("${target_INCLUDE[@]}")
761 BUILD
=("${target_BUILD[@]}")
762 DEFINE
=("${target_DEFINE[@]}")
764 NICKNAME
="$target_NICKNAME"
768 MAXTHREADS
="$target_MAXTHREADS"
771 get_server_pid_by_nickname
() {
772 # No need to save the current configuration. This function is not called
773 # in a context requiring it.
774 local target_NICKNAME
="$1"
776 # Check the status file for each running server to see if the nickname
777 # matches the one we want.
778 for f
in "$STAT_PATH"/*.stat
; do
779 test ! -e "$f" && continue
780 interpret_server_status
"$f" ||
continue
781 test "X$NICKNAME" = "X$target_NICKNAME" ||
continue
782 echo `basename "$f" | sed 's/\.stat//'` # Server with nickname was found
788 if [ ! -d "$STAT_PATH" ]; then
793 local list
=`ls | sed 's/\.stat//'`
794 if [ -z "$list" ]; then
802 eval_server_command
() {
808 clog $
"Starting $prog `echo_server_options`"
810 # Is there already a server running for the requested kernel release
812 local server_pid
=`get_server_pid_by_config`
813 if test -n "$server_pid"; then
814 if server_still_running
$server_pid; then
815 do_success $
"$prog start `echo_server_options`"
820 # Create the log directory for this server
821 prepare_log_dir
"$LOG"
822 if [ $?
-ne 0 ]; then
823 echo $
"Failed to make log directory (`dirname "$LOG"`)" >&2
827 # Construct the server start command.
828 local server_cmd
="$STAP_START_SERVER -r \"`quote_for_cmd "$RELEASE"`\" -a \"`quote_for_cmd "$ARCH"`\" $OPT_OTHER"
829 for b
in "${BUILD[@]}"; do
830 server_cmd
="$server_cmd -B \"`quote_for_cmd "$b"`\""
832 for i
in "${INCLUDE[@]}"; do
833 server_cmd
="$server_cmd -I \"`quote_for_cmd "$i"`\""
835 for d
in "${DEFINE[@]}"; do
836 server_cmd
="$server_cmd -D \"`quote_for_cmd "$d"`\""
838 test -n "$RUNTIME" && server_cmd
="$server_cmd -R \"`quote_for_cmd "$RUNTIME"`\""
839 server_cmd
="$server_cmd --log=\"`quote_for_cmd "$LOG"`\""
840 test -n "$PORT" && server_cmd
="$server_cmd --port \"`quote_for_cmd "$PORT"`\""
841 test -n "$SSL" && server_cmd
="$server_cmd --ssl \"`quote_for_cmd "$SSL"`\""
842 test -n "$MAXTHREADS" && server_cmd
="$server_cmd --max-threads \"`quote_for_cmd "$MAXTHREADS"`\""
844 # Start the server here.
846 if [ "$USER" != "`id -un`" ]; then
847 pid
=`runuser -s /bin/bash - $USER -c "$server_cmd"`
849 pid
=`eval $server_cmd`
851 if [ $?
!= 0 -o -z "$pid" ]; then
852 if [ -n "$pid" ]; then
853 rm -f "$STAT_PATH/$pid.stat"
855 do_failure $
"$prog start `echo_server_options`"
859 # Nickname defaults to the pid.
860 test -z "$NICKNAME" && NICKNAME
="$pid"
862 # Write the configuration to the status file.
863 local server_status_file
="$STAT_PATH/$pid.stat"
864 echo "ARCH=$ARCH" > "$server_status_file"
865 echo "USER=$USER" >> "$server_status_file"
866 for b
in "${BUILD[@]}"; do
867 echo "BUILD+=$b" >> "$server_status_file"
869 for i
in "${INCLUDE[@]}"; do
870 echo "INCLUDE+=$i" >> "$server_status_file"
872 for d
in "${DEFINE[@]}"; do
873 echo "DEFINE+=$d" >> "$server_status_file"
875 echo "NICKNAME=$NICKNAME" >> "$server_status_file"
876 echo "RUNTIME=$RUNTIME" >> "$server_status_file"
877 echo "RELEASE=$RELEASE" >> "$server_status_file"
878 echo "LOG=$LOG" >> "$server_status_file"
879 echo "PORT=$PORT" >> "$server_status_file"
880 echo "SSL=$SSL" >> "$server_status_file"
881 echo "MAXTHREADS=$MAXTHREADS" >> "$server_status_file"
883 do_success $
"$prog start `echo_server_options`"
886 start
() { # server-cmds
888 if [ $?
-ne 0 ]; then
889 do_failure $
"Failed to make stat directory ($STAT_PATH)"
893 # Start the specified servers
894 local server_cmds
=("$@")
896 # If none specified, start the configured servers
897 if [ -z "$server_cmds" ]; then
900 server_cmds
=("${SERVER_CMDS[@]}")
901 # If none configured, start the default servers
902 if test -z "$server_cmds"; then
903 add_distributed_options
904 server_cmds
=("${SERVER_CMDS[@]}")
905 server_cmds
+=("EXEC")
909 # Start each requested server in turn
915 for cmd
in "${server_cmds[@]}"; do
917 # Evaluate commands until the EXEC command is found.
918 if test "$cmd" != "EXEC"; then
919 eval_server_command
"$cmd"
920 # A specified nickname only sticks if it is the final command.
921 # Otherwise, we have a configuration based on a nicknamed
923 echo "$cmd" |
grep -q "^NICKNAME=" || NICKNAME
=""
926 # If a nickname was specified, but the corresponding config was not found,
927 # then it is the nickname for this new configuration.
928 if test -n "$NICKNAME_NOT_FOUND"; then
929 NICKNAME
="$NICKNAME_NOT_FOUND"
933 # Start the configured server
934 test $first = 0 && echo
938 # Don't use the same nickname for the next server.
945 stop
() { # server-cmds
948 local server_cmds
=("$@")
949 if [ -n "$server_cmds" ]; then
950 # Get the pids of all the requested servers.
954 for cmd
in "${server_cmds[@]}"; do
956 # Evaluate commands until the EXEC command is found.
957 if test "$cmd" != "EXEC"; then
958 eval_server_command
"$cmd"
959 # A specified nickname only sticks if it is the final command.
960 # Otherwise, we have a configuration based on a nicknamed
962 echo "$cmd" |
grep -q "^NICKNAME=" || NICKNAME
=""
965 # If a nickname was specified, but the corresponding config was not
966 # found, it is an error.
967 if test -n "$NICKNAME_NOT_FOUND"; then
968 clog
"No configuration found for the nickname '$NICKNAME_NOT_FOUND'"
969 NICKNAME
="$NICKNAME_NOT_FOUND"
970 do_failure $
"$prog stop `echo_server_options`"
976 # Get the pid for this server, if it's running
977 local server_pid
=`get_server_pid_by_config`
978 if test -n "$server_pid"; then
979 server_list
="$server_list $server_pid"
983 # This server is not running, but give a success stop status anyway.
984 test $first = 0 && echo
986 clog $
"Stopping $prog `echo_server_options`"
987 do_success $
"$prog stop `echo_server_options`"
990 server_list
=`managed_servers`
991 if [ -z "$server_list" ]; then
992 clog $
"Stopping $prog: " -n
993 do_success $
"$prog: No managed servers to stop"
998 # Stop each server in turn
1001 for pid
in $server_list; do
1002 if ! interpret_server_status
"$STAT_PATH/$pid.stat"; then
1007 test $first = 0 && echo
1009 clog $
"Stopping $prog `echo_server_options`"
1012 if server_still_running
$pid; then
1013 if [ "$USER" != "`id -un`" ]; then
1014 runuser
-s /bin
/bash
- $USER -c "$STAP_STOP_SERVER $pid"
1016 eval $STAP_STOP_SERVER $pid
1018 if [ $?
!= 0 ]; then
1019 do_failure $
"$prog stop `echo_server_options`"
1024 if [ $this_rc = 0 ]; then
1025 rm -f "$STAT_PATH/$pid.stat"
1026 do_success $
"$prog stop `echo_server_options`"
1033 status
() { # server-list
1036 # Report status for the specified servers or all running servers, if none
1039 local server_cmds
=("$@")
1040 if [ -n "$server_cmds" ]; then
1041 # Get the pids of all the requested servers.
1045 for cmd
in "${server_cmds[@]}"; do
1047 # Evaluate commands until the EXEC command is found.
1048 if test "$cmd" != "EXEC"; then
1049 eval_server_command
"$cmd"
1050 # A specified nickname only sticks if it is the final command.
1051 # Otherwise, we have a configuration based on a nicknamed
1053 echo "$cmd" |
grep -q "^NICKNAME=" || NICKNAME
=""
1056 # If a nickname was specified, but the corresponding config was not
1058 if test -n "$NICKNAME_NOT_FOUND"; then
1059 echo "No configuration found for the nickname '$NICKNAME_NOT_FOUND'"
1065 # Get the pid for this server, if it's running
1066 local server_pid
=`get_server_pid_by_config`
1067 if test -n "$server_pid"; then
1068 server_list
="$server_list $server_pid"
1071 # This server is not running
1072 echo "stap-server `echo_server_options` is not running"
1076 server_list
=`managed_servers`
1077 if [ -z "$server_list" ]; then
1078 echo "No managed stap-server is running"
1083 # Get status of each server in turn
1085 for pid
in $server_list; do
1086 if ! interpret_server_status
"$STAT_PATH/$pid.stat"; then
1090 if ! server_still_running
$pid; then
1091 echo "stap-server `echo_server_options` started as PID $pid is no longer running"
1095 echo "stap-server `echo_server_options` running as PID $pid"
1101 # Restart or start if not running
1102 function restart
() { # server-cmds
1103 # Restart the specified servers or all servers, if none specified.
1105 local server_cmds
=("$@")
1106 if [ -z "$server_cmds" ]; then
1107 local server_list
=`managed_servers`
1109 for pid
in $server_list; do
1110 if ! interpret_server_status
"$STAT_PATH/$pid.stat"; then
1116 server_cmds
+=("${SERVER_CMDS[@]}")
1117 server_cmds
+=("EXEC")
1121 # Stop the specified servers, or all if none specified
1122 stop
"${server_cmds[@]}" || rc
=1
1125 # Restart the same servers. If none were specified then
1126 # start the configured or default server(s)).
1127 start
"${server_cmds[@]}"
1129 [ $this_rc != 0 ] && rc
=$this_rc
1134 # Restart only if running
1135 function condrestart
() { # server-list
1136 # Restart the specified servers or all servers, if none specified,
1137 # but only if they are already running.
1139 local server_cmds
=("$@")
1140 if [ -z "$server_cmds" ]; then
1141 local server_list
=`managed_servers`
1143 for pid
in $server_list; do
1144 if ! interpret_server_status
"$STAT_PATH/$pid.stat"; then
1150 server_cmds
+=("${SERVER_CMDS[@]}")
1151 server_cmds
+=("EXEC")
1153 # No server specified or running?
1154 if [ -z "$server_cmds" ]; then
1155 clog
"No managed stap-server is running" -n
1156 do_success
"No managed stap-server is running"
1161 # For each server in the list, stop it if it is running
1163 local this_server_cmds
1165 for cmd
in "${server_cmds[@]}"; do
1166 # Execute and collect commands until the EXEC command is found.
1167 this_server_cmds
+=("$cmd")
1168 if test "$cmd" != "EXEC"; then
1169 eval_server_command
"$cmd"
1173 test $first = 0 && echo
1176 # Now see if this server is running
1177 if ! status
"${this_server_cmds[@]}" >/dev
/null
2>&1; then
1178 clog $
"$prog `echo_server_options` is not running"
1179 do_success
"$prog `echo_server_options` is not running"
1180 unset this_server_cmds
1184 start_cmds
+=("${this_server_cmds[@]}")
1186 stop
"${this_server_cmds[@]}"
1188 [ $this_rc != 0 ] && rc
=$this_rc
1190 unset this_server_cmds
1193 # Now restart the servers that were running
1194 if [ -n "$start_cmds" ]; then
1196 start
"${start_cmds[@]}"
1198 [ $this_rc != 0 ] && rc
=$this_rc
1204 #------------------------------------------------------------------
1206 #------------------------------------------------------------------
1210 prepare_log_dir
"$LOG_FILE"
1211 if [ $?
-ne 0 ]; then
1212 echo $
"Failed to make log directory (`dirname $LOG_FILE`)" >&2
1216 OPTS
=`getopt -s bash -u --options 'a:B:c:D:iI:n:p:kPr:R:u:' \
1217 --longoptions 'log:' \
1218 --longoptions 'port:' \
1219 --longoptions 'ssl:' \
1220 --longoptions 'max-threads:' \
1222 if [ $?
-ne 0 ]; then
1223 echo "Error: Argument parse error: $@" >&2
1228 # Initialize server specs
1229 parse_args
"$@" ||
exit 2
1235 start
) # Start specified servers. If none specified, start configured servers
1236 start
"${SERVER_CMDS[@]}"
1239 stop
) # Stop specified servers
1240 stop
"${SERVER_CMDS[@]}"
1243 restart
) # Restart specified servers
1244 restart
"${SERVER_CMDS[@]}"
1247 condrestart|try-restart
) # Restart specified servers if they are running
1248 condrestart
"${SERVER_CMDS[@]}"
1251 status
) # Give status on specified servers
1252 status
"${SERVER_CMDS[@]}"
1255 reload
) # Reloading config without stop/restart is not supported
1258 force-reload
) # Reload config with stop/start
1259 # stop all running servers
1262 # Restart specified servers
1263 # If none specified, restart configured servers
1264 start
"${SERVER_CMDS[@]}"