Bug 32578

Summary: FR: supply a default simple implementation if condrestart is missing in init-script
Product: Sisyphus Reporter: Ivan Zakharyaschev <imz>
Component: serviceAssignee: placeholder <placeholder>
Status: NEW --- QA Contact: qa-sisyphus
Severity: enhancement    
Priority: P3 CC: glebfm, ldv, legion, placeholder, stanv, viy
Version: unstable   
Hardware: all   
OS: Linux   
Bug Depends on:    
Bug Blocks: 32577    

Description Ivan Zakharyaschev 2016-10-05 19:41:02 MSK
service-0.5.26-alt1

Something like this could be used to fallback to a default implementation:

service "$1" condrestart || if service "$1" status >/dev/null; then service "$1" restart; fi

This would be useful for init-scripts written for Debian which are able to function thanks to /lib/lsb/init-functions (from lsb-init), but usually lack a condrestart command.

This would make lsb-init more useful and powerful for the cases when a Debian init-script is borrowed into ALT Sisyphus.

Potential cases:

# apt-cache whatdepends lsb-init
lsb-init-4.0-alt5
  starboard-preinstall-1.0-alt4
    Depends: lsb-init
  owamp-server-3.5.0-alt1
    Depends: lsb-init >= 4.0-alt4
    Depends: </lib/lsb/init-functions>
      lsb-init-4.0-alt5
  lsb-core-4.0-alt5
    Depends: lsb-init = 4.0
  tomcat-1:8.0.32-alt4_4jpp8
    Depends: </lib/lsb/init-functions>
      lsb-init-4.0-alt5
  laptop-mode-tools-1.70-alt1
    Depends: </lib/lsb/init-functions>
      lsb-init-4.0-alt5
  xtreemfs-server-1.5.1-alt1
    Depends: </lib/lsb/init-functions>
      lsb-init-4.0-alt5
  xen-runtime-4.7.0-alt1
    Depends: </lib/lsb/init-functions>
      lsb-init-4.0-alt5
  turbovnc-server-1.2.1-alt3
    Depends: </lib/lsb/init-functions>
      lsb-init-4.0-alt5
  thermald-1.5.3-alt2
    Depends: </lib/lsb/init-functions>
      lsb-init-4.0-alt5
  drbd83-tools-8.3.8-alt3
    Depends: </lib/lsb/init-functions>
      lsb-init-4.0-alt5
  drbd-tools-8.3.16-alt1
    Depends: </lib/lsb/init-functions>
      lsb-init-4.0-alt5
  ceph-0.94.9-alt2
    Depends: </lib/lsb/init-functions>
      lsb-init-4.0-alt5


+++ This bug was initially created as a clone of Bug #32577 +++

laptop-mode-tools-1.70-alt1

ALT's /usr/sbin/post_service invokes the init-script's condrestart command:

                service "$1" condrestart

but the Debian-style /etc/init.d/laptop-mode doesn't have it (similarly to all other Debian-style init-scripts).

I've patched some other Debian-style init-scripts for this ("condrestart") in a simple way:

http://git.altlinux.org/gears/o/owamp.git?p=owamp.git;a=commitdiff;h=ae7ac80b0eb4dd255d8918791a5b06099d69305e

diff --git a/debian/owamp-server.init b/debian/owamp-server.init
index 1a7998b..24951c3 100755
--- a/debian/owamp-server.init
+++ b/debian/owamp-server.init
@@ -122,8 +122,18 @@ case "$1" in
 		;;
 	esac
 	;;
+  condrestart|condreload)
+        if "$0" status >/dev/null; then
+            exec "$0" restart
+        fi
+        ;;
+  condstop)
+        if "$0" status >/dev/null; then
+            exec "$0" stop
+        fi
+        ;;
   *)
-	echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
+	echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload|condrestart|condreload|condstop}" >&2
 	exit 3
 	;;
 esac

A very similar patch:

http://git.altlinux.org/gears/t/thermald.git?p=thermald.git;a=commitdiff;h=5e6857d421e2bd21323bb831ec500308cb049130

Perhaps, this trick can be moved into package service (instead of patching each individual package). (I'm going to submit such a FR.)