[lxc-devel] [lxc/master] don't make sysv init scripts dependant on distribution specifics

evgeni on Github lxc-bot at linuxcontainers.org
Fri Apr 15 19:13:38 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 805 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160415/6b556f51/attachment.bin>
-------------- next part --------------
From 25167ac895c307b7d239196ddadb4a48ed368248 Mon Sep 17 00:00:00 2001
From: Evgeni Golov <evgeni at debian.org>
Date: Fri, 15 Apr 2016 20:45:09 +0200
Subject: [PATCH] don't make sysv init scripts dependant on distribution
 specifics

- /etc(/rc.d)?/init.d/functions does not exist on all distributions
- LSB does not define a message function without an explicit status
- Debian-derived systems add a log_daemon_msg for that

lets define an own log_daemon_msg as echo and try to load LSB init
functions afterwards, which might overload it with a nicer version

that way the init scripts should work on any system, without hard
dependencies on neither LSB nor /etc/init.d/functions

Signed-off-by: Evgeni Golov <evgeni at debian.org>
---
 config/init/sysvinit/lxc-containers.in | 28 ++++++++++++----------------
 config/init/sysvinit/lxc-net.in        | 28 ++++++++++++----------------
 2 files changed, 24 insertions(+), 32 deletions(-)

diff --git a/config/init/sysvinit/lxc-containers.in b/config/init/sysvinit/lxc-containers.in
index f4ce8ea..3b38393 100644
--- a/config/init/sysvinit/lxc-containers.in
+++ b/config/init/sysvinit/lxc-containers.in
@@ -17,30 +17,26 @@
 # Description: Bring up/down LXC autostart containers
 ### END INIT INFO
 
-sysconfdir="@SYSCONFDIR@"
-
-# Source function library.
-test ! -r "$sysconfdir"/rc.d/init.d/functions ||
-        . "$sysconfdir"/rc.d/init.d/functions
+# To be replaced by LSB functions, if they can be found
+# Defined here for distributions that don't have log_daemon_msg
+log_daemon_msg () {
+    echo $@
+}
 
-# provide action() fallback
-if ! type action >/dev/null 2>&1; then
-    # Real basic fallback for sysvinit "action" verbage.
-    action() {
-        echo -n "$1	"
-        shift
-        "$@" && echo "OK" || echo "Failed"
-    }
-fi
+# Try to source LSB init functions to define LSB log_* functions.
+test ! -r /lib/lsb/init-functions ||
+        . /lib/lsb/init-functions
 
 start() {
     # Setup host /dev for autodev containers.
     @LIBEXECDIR@/lxc/lxc-devsetup
-    action $"Starting LXC autoboot containers: " @LIBEXECDIR@/lxc/lxc-containers start
+    log_daemon_msg "Starting LXC autoboot containers: "
+    @LIBEXECDIR@/lxc/lxc-containers start
 }
 
 stop() {
-    action $"Stopping LXC containers: " @LIBEXECDIR@/lxc/lxc-containers stop
+    log_daemon_msg "Stopping LXC containers: "
+    @LIBEXECDIR@/lxc/lxc-containers stop
 }
 
 # See how we were called.
diff --git a/config/init/sysvinit/lxc-net.in b/config/init/sysvinit/lxc-net.in
index 95be399..187feed 100644
--- a/config/init/sysvinit/lxc-net.in
+++ b/config/init/sysvinit/lxc-net.in
@@ -17,28 +17,24 @@
 # Description: Bring up/down LXC Network Bridge
 ### END INIT INFO
 
-sysconfdir="@SYSCONFDIR@"
-
-# Source function library.
-test ! -r "$sysconfdir"/rc.d/init.d/functions ||
-        . "$sysconfdir"/rc.d/init.d/functions
+# To be replaced by LSB functions, if they can be found
+# Defined here for distributions that don't have log_daemon_msg
+log_daemon_msg () {
+    echo $@
+}
 
-# provide action() fallback
-if ! type action >/dev/null 2>&1; then
-    # Real basic fallback for sysvinit "action" verbage.
-    action() {
-        echo -n "$1	"
-        shift
-        "$@" && echo "OK" || echo "Failed"
-    }
-fi
+# Try to source LSB init functions to define LSB log_* functions.
+test ! -r /lib/lsb/init-functions ||
+        . /lib/lsb/init-functions
 
 start() {
-    action $"Starting LXC network bridge: " @LIBEXECDIR@/lxc/lxc-net start
+    log_daemon_msg "Starting LXC network bridge: "
+    @LIBEXECDIR@/lxc/lxc-net start
 }
 
 stop() {
-    action $"Stopping LXC network bridge: " @LIBEXECDIR@/lxc/lxc-net stop
+    log_daemon_msg "Stopping LXC network bridge: "
+    @LIBEXECDIR@/lxc/lxc-net stop
 }
 
 # See how we were called.


More information about the lxc-devel mailing list