Commit 4b42c3d6 authored by Jun Futagawa's avatar Jun Futagawa Committed by Michael Hanselmann

Add support to daemon-util for distributions without start-stop-daemon

This adds support to daemon-util for Red Hat based distributions that
do not have a start-stop-daemon. If /sbin/start-stop-daemon is not
available, daemon-util will source /etc/rc.d/init.d/functions.
check(), start(), and stop() are updated to use the relevant functions
from /etc/rc.d/init.d/functions.

Thanks to Stephen Fromm and Michael Hanselmann for improving the error
handling, style, and comments.
Signed-off-by: default avatarJun Futagawa <jfut@integ.jp>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent d67e0a94
...@@ -45,6 +45,12 @@ if [[ -s $defaults_file ]]; then ...@@ -45,6 +45,12 @@ if [[ -s $defaults_file ]]; then
. $defaults_file . $defaults_file
fi fi
# Meant to facilitate use utilities in /etc/rc.d/init.d/functions in case
# start-stop-daemon is not available.
_ignore_error() {
eval "$@" || :
}
_daemon_pidfile() { _daemon_pidfile() {
echo "@LOCALSTATEDIR@/run/ganeti/$1.pid" echo "@LOCALSTATEDIR@/run/ganeti/$1.pid"
} }
...@@ -176,9 +182,17 @@ check() { ...@@ -176,9 +182,17 @@ check() {
fi fi
local name="$1"; shift local name="$1"; shift
local pidfile=$(_daemon_pidfile $name)
start-stop-daemon --stop --signal 0 --quiet \ local daemonexec=$(_daemon_executable $name)
--pidfile $(_daemon_pidfile $name)
if type -p start-stop-daemon >/dev/null; then
start-stop-daemon --stop --signal 0 --quiet \
--pidfile $pidfile
else
_ignore_error status \
-p $pidfile \
$daemonexec
fi
} }
# Starts a daemon # Starts a daemon
...@@ -189,6 +203,9 @@ start() { ...@@ -189,6 +203,9 @@ start() {
fi fi
local name="$1"; shift local name="$1"; shift
local pidfile=$(_daemon_pidfile $name)
local usergroup=$(_daemon_usergroup $plain_name)
local daemonexec=$(_daemon_executable $name)
if [[ "$name" == ganeti-confd && if [[ "$name" == ganeti-confd &&
"@CUSTOM_ENABLE_CONFD@" == False ]]; then "@CUSTOM_ENABLE_CONFD@" == False ]]; then
...@@ -205,11 +222,20 @@ start() { ...@@ -205,11 +222,20 @@ start() {
@PKGLIBDIR@/ensure-dirs @PKGLIBDIR@/ensure-dirs
start-stop-daemon --start --quiet --oknodo \ if type -p start-stop-daemon >/dev/null; then
--pidfile $(_daemon_pidfile $name) \ start-stop-daemon --start --quiet --oknodo \
--startas $(_daemon_executable $name) \ --pidfile $pidfile \
--chuid $(_daemon_usergroup $plain_name) \ --startas $daemonexec \
-- $args "$@" --chuid $usergroup \
-- $args "$@"
else
# TODO: Find a way to start daemon with a group, until then the group must
# be removed
_ignore_error daemon \
--pidfile $pidfile \
--user ${usergroup%:*} \
$daemonexec $args "$@"
fi
} }
# Stops a daemon # Stops a daemon
...@@ -220,9 +246,14 @@ stop() { ...@@ -220,9 +246,14 @@ stop() {
fi fi
local name="$1"; shift local name="$1"; shift
local pidfile=$(_daemon_pidfile $name)
start-stop-daemon --stop --quiet --oknodo --retry 30 \ if type -p start-stop-daemon >/dev/null; then
--pidfile $(_daemon_pidfile $name) start-stop-daemon --stop --quiet --oknodo --retry 30 \
--pidfile $pidfile
else
_ignore_error killproc -p $pidfile $name
fi
} }
# Starts a daemon if it's not yet running # Starts a daemon if it's not yet running
...@@ -275,6 +306,12 @@ reload_ssh_keys() { ...@@ -275,6 +306,12 @@ reload_ssh_keys() {
@RPL_SSH_INITD_SCRIPT@ restart @RPL_SSH_INITD_SCRIPT@ restart
} }
# Read @SYSCONFDIR@/rc.d/init.d/functions if start-stop-daemon not available
if ! type -p start-stop-daemon >/dev/null && \
[[ -f @SYSCONFDIR@/rc.d/init.d/functions ]]; then
_ignore_error . @SYSCONFDIR@/rc.d/init.d/functions
fi
if [[ "$#" -lt 1 ]]; then if [[ "$#" -lt 1 ]]; then
echo "Usage: $0 <action>" >&2 echo "Usage: $0 <action>" >&2
exit 1 exit 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment