diff mbox

opensm: Add support for PID file

Message ID 20110712162740.29e2d7d1.weiny2@llnl.gov (mailing list archive)
State Rejected, archived
Delegated to: Alex Netes
Headers show

Commit Message

Ira Weiny July 12, 2011, 11:27 p.m. UTC
I agree this is an issue.  However, usually the PID is generated from the
startup script so that only the PID which is started by it is stopped.

Specifically, think of the use case of starting multiple SM's on different
ports.  For example a local user may do this to manage 2 subnets from one
node.  Your patch will, by default, overwrite the PID file with each instance.
(yes --pid-file can be specified but this is not very standard.)

I think a better (and more standard) approach is to do the following (untested):


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

Comments

Jason Gunthorpe July 12, 2011, 11:52 p.m. UTC | #1
On Tue, Jul 12, 2011 at 04:27:40PM -0700, Ira Weiny wrote:

> -    @sbindir@/opensm --daemon $OPTIONS > /dev/null
> +    daemon --pidfile=$PIDFILE @sbindir@/opensm --daemon $OPTIONS > /dev/null

You need to drop the --daemon from opensm if you run it under daemon..

The usual way to do this is to have the daemon drop a pidfile to the
location set by its --pidfile argument after it forks, but before the
command returns.

If --pidfile is not given it should not drop a pidfile anyplace.

Generally the daemon should make sure it can run without exiting
before forking, which is why this approach is prefered to using the
daemon command.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ira Weiny July 12, 2011, 11:58 p.m. UTC | #2
On Tue, 12 Jul 2011 16:52:22 -0700
Jason Gunthorpe <jgunthorpe@obsidianresearch.com> wrote:

> On Tue, Jul 12, 2011 at 04:27:40PM -0700, Ira Weiny wrote:
> 
> > -    @sbindir@/opensm --daemon $OPTIONS > /dev/null
> > +    daemon --pidfile=$PIDFILE @sbindir@/opensm --daemon $OPTIONS > /dev/null
> 
> You need to drop the --daemon from opensm if you run it under daemon..
> 
> The usual way to do this is to have the daemon drop a pidfile to the
> location set by its --pidfile argument after it forks, but before the
> command returns.

You mean like Alex's patch did?  I have not seen this done before.  I checked out apache's httpd command and I don't see it doing this.

> 
> If --pidfile is not given it should not drop a pidfile anyplace.

"it" is opensm in this case?

> 
> Generally the daemon should make sure it can run without exiting
> before forking, which is why this approach is prefered to using the
> daemon command.

Ok, perhaps I am backwards, as I said I have not seen this done before.

Ira

> 
> Jason
Jason Gunthorpe July 13, 2011, 4:14 a.m. UTC | #3
On Tue, Jul 12, 2011 at 04:58:17PM -0700, Ira Weiny wrote:

> > The usual way to do this is to have the daemon drop a pidfile to the
> > location set by its --pidfile argument after it forks, but before the
> > command returns.
> 
> You mean like Alex's patch did?  I have not seen this done before.
> I checked out apache's httpd command and I don't see it doing this.

I didn't look closely..

At least sshd, ntpd, acpid, and dbus are working that way on my ubuntu
system.. Some commands write a default pidfile automaticaly rather
than doing nothing, but upstart and systemd eliminate the need
for a pid file at all, so I prefer to see a no write option.

> > If --pidfile is not given it should not drop a pidfile anyplace.
> 
> "it" is opensm in this case?

Yes

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/scripts/opensm.init.in b/scripts/opensm.init.in
index 0c84bd3..1e053c4 100644
--- a/scripts/opensm.init.in
+++ b/scripts/opensm.init.in
@@ -42,6 +42,8 @@ 

 prefix=@prefix@
 exec_prefix=@exec_prefix@
+piddir=@localstatedir@
+PIDFILE=${piddir}/opensm.pid

 # Source function library.
 if [[ -s /etc/init.d/functions ]]; then
@@ -62,7 +64,7 @@  fi

 start () {
     echo -n "Starting opensm: "
-    @sbindir@/opensm --daemon $OPTIONS > /dev/null
+    daemon --pidfile=$PIDFILE @sbindir@/opensm --daemon $OPTIONS > /dev/null
     if [[ $RETVAL -eq 0 ]]; then
         touch /var/lock/subsys/opensm
         success
@@ -74,7 +76,7 @@  start () {

 stop () {
     echo -n "Shutting down opensm: "
-    killproc opensm
+    killproc -p $PIDFILE opensm
     if [[ $RETVAL -eq 0 ]]; then
         rm -f /var/lock/subsys/opensm
         success
@@ -85,7 +87,8 @@  stop () {
 }

 Xstatus () {
-       pid="`pidof opensm`"
+       pid=`cat $PIDFILE`
+       ps -p $pid
        ret=$?
        if [ $ret -eq 0 ] ; then
                echo "OpenSM is running... pid=$pid"
@@ -117,11 +120,11 @@  case "$1" in
        [ -e /var/lock/subsys/opensm ] && restart
        ;;
     resweep)
-       killall -HUP opensm
+       kill -s 1 `cat $PIDFILE`
         RETVAL=$?
        ;;
     rotatelog)
-       killall -USR1 opensm
+       kill -s 10 `cat $PIDFILE`
         RETVAL=$?
        ;;
     *)