diff options
Diffstat (limited to 'initscript')
-rw-r--r-- | initscript/README.stap-server | 284 | ||||
-rw-r--r-- | initscript/README.systemtap (renamed from initscript/README.initscript) | 2 | ||||
-rw-r--r-- | initscript/config.stap-server | 5 | ||||
-rw-r--r-- | initscript/config.systemtap (renamed from initscript/config) | 0 | ||||
-rw-r--r-- | initscript/stap-server.in | 547 |
5 files changed, 837 insertions, 1 deletions
diff --git a/initscript/README.stap-server b/initscript/README.stap-server new file mode 100644 index 00000000..a09859b0 --- /dev/null +++ b/initscript/README.stap-server @@ -0,0 +1,284 @@ +stap-server initscript +Version 0.1.0 + +INDEX +===== +1. Introduction +2. Usage +3. Files +4. Configuration Format +5. Usage Examples + +1. Introduction +=============== +The stap-server init script aims to provide +- management of systemtap compile servers as a service. +- convenient control over configured servers and individual (ad-hoc) servers. + +2. Usage +======== +2.1 Synopsis +------------ + /sbin/service stap-server {start|stop|restart|condrestart|try-restart|force-reload|status} [options] + +2.2 Actions +----------- +One of the actions below must be specified. + +2.2.1 start + Start server(s). If a specified server is already started, this action will + be ignored for that server. If any server fails to start this action fails. + If no server is specified, the configured servers are started. If no servers + are configured, a server for the kernel release and architecture of the host + is started. + +2.2.2 stop + Stop server(s). If a specified server is already stopped, this action + will be ignored for that server. If a server fails to stop, this action fails. + If no server is specified, all currently running servers are stopped. + +2.2.3 restart + Stop and start servers again. The specified servers are stopped and restarted. + If no server is specified, all currently running servers are stopped and + restarted. If no servers are running this action behaves like 'start'. + +2.2.4 condrestart + Stop and start servers again. The specified servers are stopped and restarted. + If a specified server is not running, it is not started. If no server is + specified, all currently running servers are stopped and restarted. If no + servers are running, none will be started. + +2.2.5 try-restart + This action is identical to condrestart. + +2.2.6 force-reload + Stop all running servers, reload config files and restart the service as if + 'start' was specified. + +2.2.7 status + Print information about running servers. Information about the specified + server(s) will be printed. If no server is specified, information about all + running servers will be printed. + +2.3 Options +----------- +The following options may be used to provide additional configuration and +to specify servers to be managed. + +2.3.1 -c configfile + This option specifies a configuration file in addition to those described + in section 4 below. This file will be processed after the default + configuration file. If the -c option is specified more than once, the last + configuration file specified will be used. + +2.3.2 -a architecture + Each stap-server instance targets a specific kernel release and target + architecture. This option specifies the target architecture to be associated + with subsequent -r options. The default architecture is the architecture of + the host. + +2.3.3 -r kernel-release + This option specifies a server for the given kernel release and the current + target architecture (specified by a previous -a option, or the default). The + arguments accepted by this option are the same as for stap itself. See stap(1) + for more details. + +2.3.4 -i + This option is a shortcut which specifies one server for each kernel + release installed in /lib/modules/. The default architecture is associated + with these servers (i.e. previous -a has no effect). + +3. Files +======== +3.1 stap-server +--------------- +/etc/init.d/stap-server + +This is the stap-server initscript. + +3.2 Configuration files +----------------------- +Configuration files are written in bash script. + +3.2.1 Global config file + /etc/sysconfig/stap-server + + This config file is for global configuration (see section 4.1). + +3.2.2 Server config files + /etc/stap-server/conf.d/*.conf + + The config files under this directory are for each server to be started by + default (see section see 4.2). + +3.3 Message Log +--------------- +/var/log/stap-server.log + +All messages including server errors and detailed messages are sent +to this file. +Some error and warning messages are also sent to console and syslogd (syslog +output is optional, because this service may start before syslog). + +3.4 Status files +---------------- +/var/run/stap-server/<server_spec> + +4. Configuration Format +======================= +Configuration files allows us to + - specify global configuration of logging, server configuration files, status + files and other global parameters. + - specify which servers are to be started by default. + +4.1 Global Configuration file (/etc/sysconfig/stap-server) +---------------------------------------------------------- +The global configuration file may contain settings for the following +variables. + +4.1.1 CONFIG_PATH + Specify the absolute path of the directory containing the default server + configurations. + (default: /etc/stap-server/conf.d) + +4.1.2 STAT_PATH + Specify the absolute path of the running server status directory. + (default: /var/run/stap-server) + +4.1.3 LOG_FILE + Specify the absolute path of the log file + (default: /var/log/stap-server.log) + +4.1.4 STAP_USER + Specify the userid which will be used to run the server(s). + (default: stap-server) + +4.2 Individual server configuration (/etc/stap-server/conf.d/*.conf) +-------------------------------------------------------------------- +Each server configuration file configures a server to be started when no +server is specified for the 'start' action. + +4.2.1 ARCH + Specify the target architecture for this server. If ARCH is not set, the + architecture of the host will be used. + +4.2.2 RELEASE + Specify the kernel release for this server. If RELEASE is not set, the release + of the kernel running on the host will be used. + +4.3 Configuration Example +------------------------- + +4.3.1 Global Config Example (/etc/sysconfig/stap-server) + --- + CONFIG_PATH=~<user>/my-stap-server-configs + LOG_FILE=/tmp/stap-server.log + --- + +4.3.2 Server Config Examples (/etc/stap-server/conf.d/*.conf) + --- file1.conf + ARCH=i386 + RELEASE=2.6.18-128.el5 + --- file2.conf + ARCH=powerpc + RELEASE=/kernels/2.6.18-92.1.18.el5/build + --- + +5. Usage Eamples +================ + +5.1 Package Installation +------------------------ +After installing the systemtap package, install the systemtap-server package. +# yum install systemtap-server +This package will include the initscript, default configuration files and +other files. + +5.2 Testing +----------- +See if the default service operates correctly. + # service stap-server start + # service stap-server status + # service stap-server restart + # service stap-server status + # service stap-server condrestart + # service stap-server status + # service stap-server force-relooad + # service stap-server status + # service stap-server stop + # service stap-server status + # service stap-server condrestart + # service stap-server status # <---no server should be running + +If there are no errors, the service is correctly installed. + +5.3 Service Enabling +-------------------- +After all test have passed, enable the stap-server initscript. +# chkconfig stap-server on + +5.4 Starting Specific Servers +----------------------------- +5.4.1 Starting a server for an installed kernel release + + # service stap-server start -r <release> + + where <release> refers to a kernel installed in /lib/modules + +5.4.2 Starting servers for all installed kernel releases + + # service stap-server start -i + +5.4.3 Starting a server for a kernel release not installed (cross compiling) + + # service stap-server start -a <arch> -r /<builddir> + + where <arch> is the target architecture and + <buildder> is the absolute path to the kernel's build tree. + +5.5 Managing Specific Servers +----------------------------- +Specifying an architecture and/or release for all other actions will act on +that server alone (if it is running). For example + + # service stap-server status -r 2.6.18-128.el5 + # service stap-server restart -a i386 -r 2.6.18-92.1.18.el5 + # service stap-server stop -a powerpc -r /kernels/2.6.18-92.1.18.el5/build + +5.6 Configuring Default Servers +------------------------------- +5.6.1 Create Server Config Files + Each file in /etc/stap-server/conf.d/*.conf represents a server to be started + by default if no servers are specifued on the 'start' action. Each such + config file may set the ARCH and/or RELEASE variables which correspond to the + -a and -r command line options respectively. + + # vi /etc/stap-server/conf.d/2.6.18-128.el5.conf + ARCH= # default arch + RELEASE=2.6.18-128.el5 + + # vi /etc/stap-server/conf.d/powerpc.conf + ARCH=powerpc + RELEASE= #default release + + # vi /etc/stap-server/conf.d/native.conf + ARCH= #default arch + RELEASE= #default release + +5.6.2 Starting Default Servers + + # service stap-server start + +5.6.2 Restarting After Changing the Configuration + + To restart the service after global configuration changes and/or when default + servcers have been added to removed: + + # service stap-server force-reload + +5.7 Stopping the stap-server Service +------------------------------------ + + To stop all running servers: + + # service stap-server stop diff --git a/initscript/README.initscript b/initscript/README.systemtap index c7bb4888..5c6cac15 100644 --- a/initscript/README.initscript +++ b/initscript/README.systemtap @@ -209,7 +209,7 @@ Configuration file allows us 4.1.11 ALLOW_CACHEONLY If this is set 'yes', systemtap initscript list up cache-only scripts too. - *NOTE*: systemtap initscript will load unexpected obsolate caches with this + *NOTE*: systemtap initscript will load unexpected obsolete caches with this option. You should check cache directory before enabling this option. (default: no) diff --git a/initscript/config.stap-server b/initscript/config.stap-server new file mode 100644 index 00000000..ad0c9c4d --- /dev/null +++ b/initscript/config.stap-server @@ -0,0 +1,5 @@ +# Path setup +# CONFIG_PATH=/etc/stap-server/conf.d +# STAT_PATH=/var/run/stap-server +# LOG_FILE=/var/log/stap-server.log +# STAP_USER=stap-server diff --git a/initscript/config b/initscript/config.systemtap index c49a34a5..c49a34a5 100644 --- a/initscript/config +++ b/initscript/config.systemtap diff --git a/initscript/stap-server.in b/initscript/stap-server.in new file mode 100644 index 00000000..f00110b0 --- /dev/null +++ b/initscript/stap-server.in @@ -0,0 +1,547 @@ +#!/bin/bash +# +# stap-server init.d script for the systemtap compile server +# +# chkconfig: - 00 99 +# description: The systemtap compile server provides a centralized and secure \ +# environment for compiling systemtap scripts. +# config: /etc/sysconfig/stap-server +# config: /etc/stap-server/conf.d + +BINDIR=@bindir@ + +# Source function library. +. /etc/rc.d/init.d/functions + +# Systemtap function library +. $BINDIR/stap-env + +prog=stap-server + +# Commands +STAP_START_SERVER=$BINDIR/stap-start-server +STAP_STOP_SERVER=$BINDIR/stap-stop-server +UNAME=/bin/uname + +# Path setup +CONFIG_FILE=/etc/sysconfig/stap-server +CONFIG_PATH=/etc/stap-server/conf.d +STAT_PATH=/var/run/stap-server +LOG_FILE=/var/log/stap-server.log + +# Default Settings +STAP_USER=stap-server + +# Default option settings +# Target architecture +OPT_KERNEL_ARCH=`stap_get_arch` +# A list of release_arch pairs +OPT_SERVER_LIST= +# Optional global config file +OPT_CONFIG_FILE= + +echo_usage () { + echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|status} [options]" + echo $"Options:" + echo $" -c configfile : specify additional config file" + echo $" -a arch : change the target architecture" + echo $" -r release : specify a kernel release" + echo $" -i : specify all installed kernel releases" + echo $"" + echo $"All options, except -c, may be specified more than once." + echo $"" + echo $"Each -a option changes the target architecture for subsequent -r" + echo $"options. The default is the architecture of the host platform." + echo $"" + echo $"Each -r option specifies a server for the given kernel release and the" + echo $"current architecture (either the default or set by the previous -a" + echo $"option)." + echo $"" + echo $"The -i option is a shortcut which specifies one server for each kernel" + echo $"release installed in /lib/modules/. The default architecture is used" + echo $"for these servers." + echo $"" + echo $"The specified action is performed on each server specified on the command line." + echo $"If no servers are specified on the command line, the behavior is as follows:" + echo $"" + echo $" start: Start the servers configured in /etc/stap-server/conf.d/*.conf." + echo $" If none are configured, start a server for the kernel release" + echo $" and architecture of the host platform." + echo $"" + echo $" stop: Stop all currently running servers." + echo $"" + echo $" restart: Restart all currently running servers. If no servers are running," + echo $" behave as if 'start' was specified." + echo $"" + echo $" condrestart: Restart all currently running servers. If no servers are running," + echo $" do nothing." + echo $"" + echo $" try-restart: Same as condrestart." + echo $"" + echo $" force-reload: Stop all currently running servers and behave as if 'start'" + echo $" was specified." + echo $"" + echo $" status: Report the status of all current running servers." + echo $"" +} + +#----------------------------------------------------------------- +# Helper functions +#----------------------------------------------------------------- +log () { # message + echo `LC_ALL=en date +"%b %e %T"`": $1" >> "$LOG_FILE" +} +clog () { # message [-n] + echo $2 "$1" + log "$1" +} +slog () { # message + logger "$1" # if syslogd is running, this message will be sent to syslog. + log "$1" +} +logex () { # command + eval log \"Exec: $@\" + "$@" >> "$LOG_FILE" 2>&1 + return $? +} +do_failure () { # message + slog "Error: $1" + failure "$1" +} +do_success () { # message + log "Pass: $1" + success "$1" +} + +#------------------------------------------------------------------ +# Parameter parsing and setup options +#------------------------------------------------------------------ +parse_args () { # arguments + local rc=0 + while [ -n "$1" ]; do + case "$1" in + -a) + OPT_KERNEL_ARCH=$2 + shift 1 + ;; + -c) + OPT_CONFIG_FILE=$2 + shift 1 + ;; + -i) + process_i + ;; + -r) + process_r $2 + test $? = 0 || rc=1 + shift 1 + ;; + --) + ;; + *) + rc=1 + ;; + esac + shift 1 + done + + test $rc != 0 && echo_usage + return $rc +} + +# Process the -i flag. +process_i () { + local save_arch=$OPT_KERNEL_ARCH + OPT_KERNEL_ARCH=`stap_get_arch` + + cd /lib/modules + local release + for release in `ls`; do + process_r $release + done + + OPT_KERNEL_ARCH=$save_arch + return 0 +} + +# Process the -r flag. +process_r () { + local first_char=`expr "$1" : '\(.\).*'` + + if test "$first_char" = "/"; then # fully specified path + local kernel_build_tree=$1 + local version_file_name="$kernel_build_tree/include/config/kernel.release" + # The file include/config/kernel.release within the kernel + # build tree is used to pull out the version information + local kernel_release=`cat $version_file_name 2>/dev/null` + if test "X$kernel_release" = "X"; then + echo "Missing $version_file_name" + return 1 + fi + OPT_SERVER_LIST="$OPT_SERVER_LIST ${kernel_release}_${OPT_KERNEL_ARCH}" + return 0 + fi + + # kernel release specified directly + OPT_SERVER_LIST="$OPT_SERVER_LIST ${1}_${OPT_KERNEL_ARCH}" + return 0 +} + +# Default to the currently running kernel release +get_release () { # server-spec + if [ -z "$1" ]; then + $UNAME -r + else + expr "$1" : '\(.*\)_.*' + fi +} + +# Default to the currently running kernel release +get_arch () { # server-spec + if [ -z "$1" ]; then + stap_get_arch + else + expr "$1" : '.*_\(.*\)' + fi +} + +load_config () { + # Include configs + if [ -f "$CONFIG_FILE" ]; then + . "$CONFIG_FILE" + fi + if [ -f "$OPT_CONFIG_FILE" ]; then + . "$OPT_CONFIG_FILE" + fi +} + +load_server_config () { + CONFIG_OPTS= + for f in "$CONFIG_PATH"/*.conf; do + if [ -f "$f" ]; then + # Obtain an architecture and release from each config file. + # Ensure that we get the default architecture and release if they + # are not specified. + local ARCH= + local RELEASE= + . "$f" + [ -z "$ARCH" ] && ARCH=`get_arch` + [ -z "$RELEASE" ] && RELEASE=`get_release` + CONFIG_OPTS="$CONFIG_OPTS -a $ARCH -r $RELEASE" + fi + done +} + +prepare_stat_dir () { + if [ ! -d "$STAT_PATH" ]; then + logex mkdir -p "$STAT_PATH" + [ $? -ne 0 ] && return 1 + fi + return 0 +} + +stat_file () { # server-spec + echo $STAT_PATH/$1 +} + +default_server_list () { + echo "`get_release`_`get_arch`" +} + +check_server_running () { # server-spec + local server_status=`stat_file $1` + test ! -f $server_status && return 1 + (ps -e | grep stap-serverd | grep -q `cat $server_status`) || return 1 + # Server is already running + return 0 +} + +managed_servers () { + if [ ! -d $STAT_PATH ]; then + echo "" + return 1 + fi + cd $STAT_PATH + local list=`ls` + if [ -z "$list" ]; then + echo "" + return 1 + fi + + echo "$list" +} + +start () { # server-list + prepare_stat_dir + if [ $? -ne 0 ]; then + do_failure $"Failed to make stat directory ($STAT_PATH)" + return 1 + fi + + # Start the specified servers + local server_list="$1" + # If none specified, start the configured servers + if [ -z "$server_list" ]; then + load_server_config + parse_args $CONFIG_OPTS || exit 2 + server_list="$OPT_SERVER_LIST" + + # If none configured, start the default servers + [ -z "$server_list" ] && server_list=`default_server_list` + fi + + # Start each requested server in turn + local rc=0 + local spec + local first=1 + for spec in $server_list; do + local release=`get_release $spec` + local arch=`get_arch $spec` + + test $first = 0 && echo + first=0 + clog $"Starting $prog for $release $arch: " -n + + # Is there already a server running for the requested kernel release + # and arch? + if check_server_running $spec; then + do_success $"$prog start for $release $arch" + continue + fi + + # Start the server here. + local server_status=`stat_file $spec` + runuser -s /bin/bash - $STAP_USER -c "$STAP_START_SERVER -r $release -a $arch --log=$LOG_FILE > $server_status" + if [ $? != 0 ]; then + rm -f $server_status + do_failure $"$prog start: unable to start stap-server for $release $arch" + rc=1 + fi + + do_success $"$prog start for $release $arch" + done + + return $rc +} + +stop () { # server-list + local server_status + local server_list + local first=1 + + # Stop the specified servers or all servers, if none specified. + server_list="$1" + [ -z "$server_list" ] && server_list=`managed_servers` + + # No server specified or running? + if [ -z "$server_list" ]; then + clog $"Stopping $prog: " -n + do_success $"$prog: No managed servers to stop" + return 0 + fi + + # Stop each server in turn + local rc=0 + for server_status in $server_list; do + release_arch=`echo $server_status | sed 's/_/ /'` + + test $first = 0 && echo + first=0 + clog $"Stopping $prog for $release_arch: " -n + + local this_rc=0 + local server_status_file=`stat_file $server_status` + if check_server_running $server_status; then + local pid=`cat $server_status_file` + runuser -s /bin/bash - $STAP_USER -c "$STAP_STOP_SERVER $pid" + if [ $? != 0 ]; then + do_failure $"$prog start: unable to start stap-server for $release $arch" + this_rc=1 + rc=1 + fi + fi + [ $this_rc = 0 ] && rm -f $server_status_file + + do_success $"$prog stop for $release_arch" + done + + return $rc +} + +status () { # server-list + local server_list + local rc=0 + + # Report status for the specified servers or all servers, if none specified. + server_list="$1" + [ -z "$server_list" ] && server_list=`managed_servers` + + # No server specified or running? + if [ -z "$server_list" ]; then + echo "No managed stap-server is running" + return 3 + fi + + # Get status of each server in turn + local server_status + for server_status in $server_list; do + local release_arch=`echo $server_status | sed 's/_/ /'` + local server_status_file=`stat_file $server_status` + if [ ! -f $server_status_file ]; then + echo "stap-server for $release_arch is not running" + rc=3 + else + local pid=`cat $server_status_file` + if check_server_running $server_status; then + echo "stap-server for $release_arch running as PID $pid" + else + echo "stap-server for $release_arch started as PID $pid is no longer running" + rm -f $server_status_file + rc=1 + fi + fi + done + + return $rc +} + +# Restart or start if not running +function restart () { # server-list + local server_list + + # Restart the specified servers or all servers, if none specified. + server_list="$1" + [ -z "$server_list" ] && server_list=`managed_servers` + + # Stop the specified servers, or all if none specified + stop "$server_list" + local rc=$? + echo + + # Restart the same servers. If none were specified then + # start the configured or default server(s)). + start "$server_list" + local this_rc=$? + [ $this_rc != 0 ] && rc=$this_rc + + return $rc +} + +# Restart only if running +function condrestart () { # server-list + local server_list + + # Restart the specified servers or all servers, if none specified, + # but only if they are already running. + server_list="$1" + [ -z "$server_list" ] && server_list=`managed_servers` + + # No server specified or running? + if [ -z "$server_list" ]; then + clog "No managed stap-server is running" -n + do_success "No managed stap-server is running" + return 0 + fi + + # For each server in the list, stop it if it is running + local rc=0 + local this_rc + local start_list= + local server_spec + local first=1 + for server_spec in $server_list; do + test $first = 0 && echo + first=0 + + if ! status $server_spec >/dev/null 2>&1; then + local release=`get_release $server_spec` + local arch=`get_arch $server_spec` + clog $"$prog for $release $arch is not running" -n + do_success "$prog for $release $arch is not running" + continue + fi + + start_list="$start_list $server_spec" + + stop "$server_spec" + this_rc=$? + [ $this_rc != 0 ] && rc=$this_rc + done + + # Now restart the servers that were running + for server_spec in $start_list; do + echo + start "$server_spec" + local this_rc=$? + [ $this_rc != 0 ] && rc=$this_rc + done + + return $rc +} + +#------------------------------------------------------------------ +# Mainline script +#------------------------------------------------------------------ +CMD=$1 +shift 1 +OPTS=`getopt -s bash -u -o 'a:c:ir:' -- $@` +if [ $? -ne 0 ]; then + slog "Error: Argument parse error: $@" + failure $"parse error" + echo_usage + exit 2 +fi + +parse_args $OPTS || exit 2 +load_config + +RETVAL=0 + +case $CMD in + start) + # Start specified servers. If none specified, start configured servers + start "$OPT_SERVER_LIST" + RETVAL=$? + ;; + stop) + # Stop specified servers + stop "$OPT_SERVER_LIST" + RETVAL=$? + ;; + # Restart specified servers + restart) + restart "$OPT_SERVER_LIST" + RETVAL=$? + ;; + # Restart specified servers if they are running + condrestart|try-restart) + condrestart "$OPT_SERVER_LIST" + RETVAL=$? + ;; + # Give status on specified servers + status) + status "$OPT_SERVER_LIST" + exit $? + ;; + # Reloading config without stop/restart is not supported + reload) + RETVAL=3 + ;; + # Reload config with stop/start + force-reload) + # stop all running servers + stop + echo + # Restart specified servers + # If none specified, restart configured servers + start "$OPT_SERVER_LIST" + RETVAL=$? + ;; + usage|*) + echo_usage + RETVAL=0 + ;; +esac + +echo +exit $RETVAL |