]> gitweb.michael.orlitzky.com - mjo-overlay.git/blobdiff - app-laptop/hdapsd/files/hdapsd.init.3
Rewrite the conf and init.d files a million times.
[mjo-overlay.git] / app-laptop / hdapsd / files / hdapsd.init.3
index a1fab31a6e3589b494453ab4ce190bff40ad71db..b4d0eab26b5c6a359ffd3ab97ebf5ee660a31bf0 100644 (file)
@@ -2,6 +2,17 @@
 # Copyright 1999-2014 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License, v2
 
+description="Hard Drive Active Protection System daemon"
+command="/usr/sbin/hdapsd"
+pidfile="/run/hdapsd.pid"
+
+# Always daemonize when started by OpenRC, and don't make the pidfile
+# configurable. Even if the user sets something dumb for the pidfile
+# in /etc/hdapsd.conf, we want it to work! Fortunately the settings
+# passed on the command-line override the config file.
+command_args="--background --pidfile=${pidfile}"
+
+
 depend() {
     need localmount
 }
@@ -40,28 +51,26 @@ checkconfig() {
 start() {
     checkconfig || return 1
 
-    local DISKOPTS DISK
     for DISK in ${DISKLIST}; do
-       DISKOPTS="${DISKOPTS} -d ${DISK}"
+       command_args="${command_args} -d ${DISK}"
     done
 
-    # Since we're allowed to have an empty $THRESHOLD, we append
-    # "--sensitivity $THRESHOLD" to $OPTIONS here only when it exists.
+    # Since all of these settings are now optional, we append them
+    # only if we need to.
     if [ ! -z "${THRESHOLD}" ] ; then
-       OPTIONS="${OPTIONS} --sensitivity ${THRESHOLD}"
+       command_args="${command_args} --sensitivity ${THRESHOLD}"
     fi
 
-    ebegin "Starting Hard Drive Active Protection System daemon"
-    start-stop-daemon --start --exec /usr/sbin/hdapsd \
-       --pidfile /var/run/hdapsd.pid \
-       -- --syslog --background --pidfile \
-       ${DISKOPTS} ${OPTIONS}
-    eend $?
-}
+    if [ ! -z "${SYSLOG}" ] ; then
+       command_args="${command_args} --syslog"
+    fi
+
+    if [ ! -z "${OPTIONS}" ] ; then
+       command_args="${command_args} ${OPTIONS}"
+    fi
 
-stop() {
-    ebegin "Stopping Hard Drive Active Protection System daemon"
-    start-stop-daemon --stop --exec /usr/sbin/hdapsd \
-       --pidfile /var/run/hdapsd.pid
+    ebegin "Starting the ${description}"
+    start-stop-daemon --start --exec "${command}" --pidfile "${pidfile}" \
+       -- ${command_args}
     eend $?
 }