Hi all,

I tried to minimize the changes to get close to a unit file in the systemd spirit, while still using on the init-script to keep same features as before. The patch below reflect the following actions:

1. don't auto-create the /var/*/${PROJECT_NAME} folder if not root, as it will fail anyway. 2. add a do_systemd_start function to implement the systemd-start argument that will exec' the daemon with the previously computed args. 3. since then systemd will manage the daemon, the systemd-stop argument can be removed. 4. since the script doesn't create the necessary folders anymore, create what's required using the systemd unit file.

The point 4 is where I did the most invasive choices; I assumed that
1. /var/run/${PROJECT_NAME} is not needed since PID file is not created anymore (process managed by systemd); 2. /var/lib/${PROJECT_NAME} doesn't have to be created as it is created when the package is installed;
3. /var/lock/${PROJECT_NAME}, AFAIK, is not needed when using systemd;
4. /var/log/${PROJECT_NAME} is the only one that is both required and can be considered volatile.

If any of these choices is wrong, it's easy to add the folder in the ExecStartPre lines of the systemd unit file.

If the systemd-stop argument should still be supported, I think it should be noop or print a depreciation warning.

As a consequence of these changes, the unit file doesn't need its RuntimeDirectory and PIDFile directives. Since the daemon is exec'd, the Type falls back to the default (simple) so it is removed too.

I don't how to do less than that, so here is my minimal patch proposal:

diff --git a/init-template/init-script-template b/init-template/init-script-template
index 0326b5d..fd20957 100644
--- a/init-template/init-script-template
+++ b/init-template/init-script-template
@@ -36,11 +36,13 @@ fi
 # Exit if the package is not installed
 [ -x $DAEMON ] || exit 0

-# Create /var/lock/X, /var/run/X, /var/lib/X and /var/log/X
-for i in lock run log lib ; do
-    mkdir -p /var/$i/${PROJECT_NAME}
-    chown ${SYSTEM_USER} /var/$i/${PROJECT_NAME}
-done
+# If ran as root, create /var/lock/X, /var/run/X, /var/lib/X and /var/log/X as needed
+if [ "x$USER" = "xroot" ] ; then
+    for i in lock run log lib ; do
+        mkdir -p /var/$i/${PROJECT_NAME}
+        chown ${SYSTEM_USER} /var/$i/${PROJECT_NAME}
+    done
+fi

 # This defines init_is_upstart which we use later on (+ more...)
 . /lib/lsb/init-functions
@@ -65,6 +67,10 @@ do_stop() {
     return "$RETVAL"
 }

+do_systemd_start() {
+    exec $DAEMON $DAEMON_ARGS
+}
+
 case "$1" in
 start)
     init_is_upstart > /dev/null 2>&1 && exit 1
@@ -88,11 +94,8 @@ status)
     status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
 ;;
 systemd-start)
-    do_start
+    do_systemd_start
 ;;
-systemd-stop)
-    do_stop
-;;
 restart|force-reload)
     init_is_upstart > /dev/null 2>&1 && exit 1
     log_daemon_msg "Restarting $DESC" "$NAME"
@@ -110,7 +113,7 @@ restart|force-reload)
     esac
 ;;
 *)
- echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload|systemd-start|systemd-stop}" >&2 + echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload|systemd-start}" >&2
     exit 3
 ;;
 esac
diff --git a/init-template/pkgos-gen-systemd-unit b/init-template/pkgos-gen-systemd-unit
index b97e2a9..09cf3e5 100755
--- a/init-template/pkgos-gen-systemd-unit
+++ b/init-template/pkgos-gen-systemd-unit
@@ -33,12 +33,11 @@ $AFTER
 [Service]
 User=${SYSTEM_USER}
 Group=${SYSTEM_GROUP}
+PermissionsStartOnly=true
+ExecStartPre=/bin/mkdir -p /var/log/${PROJECT_NAME}
+ExecStartPre=/bin/chown ${SYSTEM_USER}:${SYSTEM_GROUP} /var/log/${PROJECT_NAME}
 ExecStart=${SCRIPTNAME} systemd-start
-ExecStop=${SCRIPTNAME} systemd-stop
-RuntimeDirectory=${PROJECT_NAME}
-PIDFile=/var/run/${PROJECT_NAME}/${NAME}.pid
 Restart=on-failure
-Type=forking

 [Install]
 WantedBy=multi-user.target


--
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to