1 # This is a shell function library sourced by some Open vSwitch scripts.
2 # It is not intended to be invoked on its own.
4 # Copyright (C) 2009, 2010, 2011, 2012 Nicira, Inc.
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at:
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
18 ## ----------------- ##
19 ## configure options ##
20 ## ----------------- ##
22 # All of these should be substituted by the Makefile at build time.
23 logdir=${OVS_LOGDIR-'@LOGDIR@'} # /var/log/openvswitch
24 rundir=${OVS_RUNDIR-'@RUNDIR@'} # /var/run/openvswitch
25 sysconfdir=${OVS_SYSCONFDIR-'@sysconfdir@'} # /etc
26 etcdir=$sysconfdir/openvswitch # /etc/openvswitch
27 datadir=${OVS_PKGDATADIR-'@pkgdatadir@'} # /usr/share/openvswitch
28 bindir=${OVS_BINDIR-'@bindir@'} # /usr/bin
29 sbindir=${OVS_SBINDIR-'@sbindir@'} # /usr/sbin
33 LC_ALL=C; export LC_ALL
39 # Use the system's own implementations if it has any.
40 if test -e /etc/init.d/functions; then
41 . /etc/init.d/functions
42 elif test -e /etc/rc.d/init.d/functions; then
43 . /etc/rc.d/init.d/functions
44 elif test -e /lib/lsb/init-functions; then
45 . /lib/lsb/init-functions
48 # Implement missing functions (e.g. OpenSUSE lacks 'action').
49 if type log_success_msg >/dev/null 2>&1; then :; else
54 if type log_failure_msg >/dev/null 2>&1; then :; else
56 printf '%s ... failed!\n' "$*"
59 if type log_warning_msg >/dev/null 2>&1; then :; else
61 printf '%s ... (warning).\n' "$*"
64 if type action >/dev/null 2>&1; then :; else
71 log_success_msg "$STRING"
73 log_failure_msg "$STRING"
84 # This is better than "kill -0" because it doesn't require permission to
85 # send a signal (so daemon_status in particular works as non-root).
94 # drop core files in a sensible place
95 test -d "$DAEMON_CWD" || install -d -m 755 -o root -g root "$DAEMON_CWD"
100 test -d "$logdir" || install -d -m 755 -o root -g root "$logdir"
101 set "$@" --log-file="$logdir/$daemon.log"
103 # pidfile and monitoring
104 test -d "$rundir" || install -d -m 755 -o root -g root "$rundir"
105 set "$@" --pidfile="$rundir/$daemon.pid"
106 set "$@" --detach --monitor
109 if test X"$priority" != X; then
110 set nice -n "$priority" "$@"
113 action "Starting $daemon" "$@"
118 if test -e "$rundir/$1.pid"; then
119 if pid=`cat "$rundir/$1.pid"`; then
120 for action in TERM .1 .25 .65 1 1 1 1 KILL 1 1 1 1 FAIL; do
123 action "Killing $1 ($pid)" kill $pid
126 action "Killing $1 ($pid) with SIGKILL" kill -9 $pid
129 log_failure_msg "Killing $1 ($pid) failed"
133 if pid_exists $pid >/dev/null 2>&1; then
143 log_success_msg "$1 is not running"
147 pidfile=$rundir/$1.pid
148 if test -e "$pidfile"; then
149 if pid=`cat "$pidfile"`; then
150 if pid_exists "$pid"; then
151 echo "$1 is running with pid $pid"
154 echo "Pidfile for $1 ($pidfile) is stale"
157 echo "Pidfile for $1 ($pidfile) exists but cannot be read"
160 echo "$1 is not running"
165 daemon_is_running () {
166 pidfile=$rundir/$1.pid
167 test -e "$pidfile" && pid=`cat "$pidfile"` && pid_exists "$pid"