Hi Michael

On 2012/05/09 18:16, Michael Hanselmann wrote:
> Hi Jun
> 
> 2012/4/21 Jun Futagawa <[email protected]>:
>> On 2012/04/20 5:34, Michael Hanselmann wrote:
>>> In the “_ignore_error” function, can't you use “eval "$@" || :”
>>> instead of doing games with the “e” flag?
>>>
>>> Michael
>>
>> Yes. It's good idea. “eval "$@" || :” works fine!
> 
> Could you please re-send your updated patch?

I re-send the updated patch.

Thanks to Stephen and you for improving this.

Thanks,
Jun Futagawa
>From 34331ec47975b8c8987e599c6d51ea60a3fc919e Mon Sep 17 00:00:00 2001
From: Jun Futagawa <[email protected]>
Date: Tue, 15 May 2012 16:38:07 +0900
Subject: [PATCH master] 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: Jun Futagawa <[email protected]>
---
 daemons/daemon-util.in |   57 +++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 47 insertions(+), 10 deletions(-)

diff --git a/daemons/daemon-util.in b/daemons/daemon-util.in
index 03decbf..5bf2c3f 100644
--- a/daemons/daemon-util.in
+++ b/daemons/daemon-util.in
@@ -45,6 +45,12 @@ if [[ -s $defaults_file ]]; then
   . $defaults_file
 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() {
   echo "@LOCALSTATEDIR@/run/ganeti/$1.pid"
 }
@@ -176,9 +182,17 @@ check() {
   fi
 
   local name="$1"; shift
-
-  start-stop-daemon --stop --signal 0 --quiet \
-    --pidfile $(_daemon_pidfile $name)
+  local pidfile=$(_daemon_pidfile $name)
+  local daemonexec=$(_daemon_executable $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
@@ -189,6 +203,9 @@ start() {
   fi
 
   local name="$1"; shift
+  local pidfile=$(_daemon_pidfile $name)
+  local usergroup=$(_daemon_usergroup $plain_name)
+  local daemonexec=$(_daemon_executable $name)
 
   if [[ "$name" == ganeti-confd &&
         "@CUSTOM_ENABLE_CONFD@" == False ]]; then
@@ -205,11 +222,20 @@ start() {
 
   @PKGLIBDIR@/ensure-dirs
 
-  start-stop-daemon --start --quiet --oknodo \
-    --pidfile $(_daemon_pidfile $name) \
-    --startas $(_daemon_executable $name) \
-    --chuid $(_daemon_usergroup $plain_name) \
-    -- $args "$@"
+  if type -p start-stop-daemon >/dev/null; then
+    start-stop-daemon --start --quiet --oknodo \
+      --pidfile $pidfile \
+      --startas $daemonexec \
+      --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
@@ -220,9 +246,14 @@ stop() {
   fi
 
   local name="$1"; shift
+  local pidfile=$(_daemon_pidfile $name)
 
-  start-stop-daemon --stop --quiet --oknodo --retry 30 \
-    --pidfile $(_daemon_pidfile $name)
+  if type -p start-stop-daemon >/dev/null; then
+    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
@@ -275,6 +306,12 @@ reload_ssh_keys() {
   @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
   echo "Usage: $0 <action>" >&2
   exit 1
-- 
1.7.1

Reply via email to