Skip to contentSkip to conversation

/etc/init.d/opensmd: Improve systemd integration

PATCH Superseded Bart Van Assche 2 participants 3 messages Sep 14, 2012 – Sep 16, 2012 1 message not in the archive InfiniBand

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 /etc/init.d/opensmd: Improve systemd integration

On recent SLES and openSUSE systems it is necessary to read the file /lib/lsb/init-functions instead of /etc/rc.status for proper integration with systemd. Also, prevent that the opensm process is started twice and drop /var/lock/subsys/opensm.

---
 scripts/opensm.init.in |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)
scripts/opensm.init.in +15 -6
index 01d2bb9..7a9f8ec 100644
@@ -45,11 +45,18 @@ exec_prefix=@exec_prefix@
 
 # Source function library.
 if [[ -s /etc/init.d/functions ]]; then
+    # RHEL / CentOS / SL / Fedora.
     . /etc/init.d/functions
     rc_status() { :; }
     rc_exit() { exit $RETVAL; }
-fi
-if [[ -s /etc/rc.status ]]; then
+elif [[ -s /lib/lsb/init-functions ]]; then
+    # SLES / openSuSE / Debian.
+    . /lib/lsb/init-functions
+    rc_exit() { exit $RETVAL; }
+    success() { log_success_msg; }
+    failure() { log_failure_msg; }
+elif [[ -s /etc/rc.status ]]; then
+    # Older SuSE systems.
     . /etc/rc.status
     failure() { rc_status -v; }
     success() { rc_status -v; }
@@ -61,10 +68,13 @@ if [[ -s $CONFIG ]]; then
 fi
 
 start () {
+    if [ -e /var/run/opensm.pid ]; then
+	echo Already started
+	return 1
+    fi
     echo -n "Starting opensm: "
-    @sbindir@/opensm --daemon $OPTIONS > /dev/null
+    @sbindir@/opensm --daemon --pidfile /var/run/opensm.pid $OPTIONS > /dev/null
     if [[ $RETVAL -eq 0 ]]; then
-        touch /var/lock/subsys/opensm
         success
     else
         failure
@@ -76,7 +86,6 @@ stop () {
     echo -n "Shutting down opensm: "
     killproc opensm
     if [[ $RETVAL -eq 0 ]]; then
-        rm -f /var/lock/subsys/opensm
         success
     else
         failure
@@ -114,7 +123,7 @@ case "$1" in
 	restart
 	;;
     try-restart | condrestart)
-	[ -e /var/lock/subsys/opensm ] && restart
+	[ -e /var/run/opensm.pid ] && restart
 	;;
     resweep)
 	killall -HUP opensm
Signature · 6 lines
1.7.7

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
In reply to a message not in the archive

Hi Bart,

Quoted 4 lines · Bart Van Assche

On recent SLES and openSUSE systems it is necessary to read the file /lib/lsb/init-functions instead of /etc/rc.status for proper integration with systemd. Also, prevent that the opensm process is started twice and drop /var/lock/subsys/opensm.

There could be a problem (which also persists in the original script), that in theory you can run two OpenSM instances (on different ports) which is not being supported by the init script. Any thoughts how this can be addressed?

Quoted 71 lines
---
 scripts/opensm.init.in |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)
scripts/opensm.init.in +15 -6
index 01d2bb9..7a9f8ec 100644
@@ -45,11 +45,18 @@ exec_prefix=@exec_prefix@
 
 # Source function library.
 if [[ -s /etc/init.d/functions ]]; then
+    # RHEL / CentOS / SL / Fedora.
     . /etc/init.d/functions
     rc_status() { :; }
     rc_exit() { exit $RETVAL; }
-fi
-if [[ -s /etc/rc.status ]]; then
+elif [[ -s /lib/lsb/init-functions ]]; then
+    # SLES / openSuSE / Debian.
+    . /lib/lsb/init-functions
+    rc_exit() { exit $RETVAL; }
+    success() { log_success_msg; }
+    failure() { log_failure_msg; }
+elif [[ -s /etc/rc.status ]]; then
+    # Older SuSE systems.
     . /etc/rc.status
     failure() { rc_status -v; }
     success() { rc_status -v; }
@@ -61,10 +68,13 @@ if [[ -s $CONFIG ]]; then
 fi
 
 start () {
+    if [ -e /var/run/opensm.pid ]; then
+	echo Already started
+	return 1
+    fi
     echo -n "Starting opensm: "
-    @sbindir@/opensm --daemon $OPTIONS > /dev/null
+    @sbindir@/opensm --daemon --pidfile /var/run/opensm.pid $OPTIONS > /dev/null
     if [[ $RETVAL -eq 0 ]]; then
-        touch /var/lock/subsys/opensm
         success
     else
         failure
@@ -76,7 +86,6 @@ stop () {
     echo -n "Shutting down opensm: "
     killproc opensm
     if [[ $RETVAL -eq 0 ]]; then
-        rm -f /var/lock/subsys/opensm
         success
     else
         failure
@@ -114,7 +123,7 @@ case "$1" in
 	restart
 	;;
     try-restart | condrestart)
-	[ -e /var/lock/subsys/opensm ] && restart
+	[ -e /var/run/opensm.pid ] && restart
 	;;
     resweep)
 	killall -HUP opensm
Signature · 6 lines
1.7.7

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
Quoted 11 lines · Alex Netes

Hi Bart,

Quoted 4 lines · Bart Van Assche

On recent SLES and openSUSE systems it is necessary to read the file /lib/lsb/init-functions instead of /etc/rc.status for proper integration with systemd. Also, prevent that the opensm process is started twice and drop /var/lock/subsys/opensm.

There could be a problem (which also persists in the original script), that in theory you can run two OpenSM instances (on different ports) which is not being supported by the init script. Any thoughts how this can be addressed?

How about following the same approach as for srp_daemon: modify /etc/init.d/opensm such that it starts a script that starts the opensm process on all ports on which it should be started ?

Bart.

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html