Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 442878 - app-backup/tsm-6.3.0.5-r1 - pidfile does not contain correct pid, making OpenRC reporting /etc/init.d/dsmcad as crashed
Summary: app-backup/tsm-6.3.0.5-r1 - pidfile does not contain correct pid, making Open...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Martin von Gagern
URL:
Whiteboard:
Keywords: PATCH
Depends on:
Blocks:
 
Reported: 2012-11-12 15:08 UTC by Mads
Modified: 2012-12-16 11:41 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
New /etc/init.d/dsmcad-script (dsmcad,813 bytes, text/plain)
2012-11-12 15:24 UTC, Mads
Details
New /etc/init.d/dsmcad script (file_442878.txt,1.03 KB, text/plain)
2012-11-12 20:53 UTC, Mads
Details
Identify the process by name alone (gentoo442878a.diff,1.00 KB, patch)
2012-11-13 09:00 UTC, Martin von Gagern
Details | Diff
Use pgrep to save the pid (gentoo442878b.diff,1.12 KB, patch)
2012-11-13 09:05 UTC, Martin von Gagern
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mads 2012-11-12 15:08:46 UTC
/var/run/dsmcad.pid does not contain correct pid# after /etc/init.d/dsmcad start, making the service dsmcad appear to be crashed.

Reproducible: Always

Steps to Reproduce:
1. /etc/tivoli/dsm.sys:
SErvername  server_a
   COMMMethod         TCPip
   TCPPort            1500
   TCPServeraddress   <address>
     PasswordAccess generate
     NodeName source
     ErrorLogName "/var/log/tsm/dsmerror.log"
     SchedLogName "/var/log/tsm/dsmsched.log"
     exclude.dir "/usr/portage"
2. /etc/init.d/dsmcad start
Actual Results:  
# /etc/init.d/dsmcad status
 * status: crashed


Expected Results:  
# /etc/init.d/dsmcad status
 * status: started


After starting the service:

# pgrep dsmcad
8968
# cat /run/dsmcad.pid 
8964
Comment 1 Mads 2012-11-12 15:24:31 UTC
Created attachment 329346 [details]
New /etc/init.d/dsmcad-script

Quick and dirty hack which just uses pgrep to find the right PID after 5 seconds.

This can be a step in replacement for /usr/portage/app-backup/tsm/files/dsmcad.init.d
Comment 2 Tom Wijsman (TomWij) (RETIRED) gentoo-dev 2012-11-12 19:04:36 UTC
Please provide a diff (`diff -u oldFile newFile`) so it's easier to see what you have changed, thanks.
Comment 3 Jeroen Roovers (RETIRED) gentoo-dev 2012-11-12 19:20:35 UTC
Comment on attachment 329346 [details]
New /etc/init.d/dsmcad-script

--- files/dsmcad.init.d 2012-05-16 18:52:36.000000000 +0200
+++ -   2012-11-12 20:20:25.756514763 +0100
@@ -3,6 +3,8 @@
 # Distributed under the terms of the GNU General Public License v2
 # $Header: /var/cvsroot/gentoo-x86/app-backup/tsm/files/dsmcad.init.d,v 1.2 2012/05/14 16:12:10 pacho Exp $
 
+pidfile=/var/run/dsmcad.pid
+
 depend() {
         use net
         after dns dsmc
@@ -11,8 +13,12 @@
 start() {
         ebegin "Starting dsmcad"
         start-stop-daemon --start --background --nicelevel 15 \
-                --make-pidfile --pidfile /var/run/dsmcad.pid \
+                --make-pidfile --pidfile ${pidfile} \
                 --exec /opt/tivoli/tsm/client/ba/bin/dsmcad
+
+        sleep 5
+        pgrep -f /opt/tivoli/tsm/client/ba/bin/dsmcad > ${pidfile} &
+
         eend $?
 }
Comment 4 Mads 2012-11-12 20:53:47 UTC
Created attachment 329380 [details]
New /etc/init.d/dsmcad script

Ah, thanks for adding the patch. Noticed I forgot to do the ${pidfile} exchange inside stop(), so I redid it.
Comment 5 Martin von Gagern 2012-11-13 09:00:09 UTC
Created attachment 329446 [details, diff]
Identify the process by name alone

It's a bit ugly that dsmcad does background without writing the child pid to a f file, but I've found no way to disable this behaviour. This leaves us with two options: 

A) Identify the process by name alone
B) Use the name to find the pid immediately after the process was started

B has some chances of keeping track of the correct process even if more than one instance are running. But it also has some chances of getting the wrong one from time to time if two instances are started at the same time. A is simpler and should suffice for almost all realistic usage scenarios. I'll attach patches for both, but am in favour of A due to its simplicity.

In any case, the --make-pidfile, --pidfile and --background arguments to start-stop-daemon must be removed. If the program does backrgound itself, there is no gain and much harm in s-s-d doing the same.
Comment 6 Martin von Gagern 2012-11-13 09:05:04 UTC
Created attachment 329448 [details, diff]
Use pgrep to save the pid

This patch does implement option B. It is an improved version of what Mads submitted earlier.

Once --background is gone from the s-s-d options, there is no need to sleep and wait for the final daemon process to start up. The parent will only exit after the child has been created, so once s-s-d returns, the child will already be running. No point in backgrounding the pgrep either, as far as I can see.

I added -x to pgrep to force an exact match, and -n to only ever return a single pid, namely that of the most recently started process. Without this latter option, there is no benefit in saving the pid, as the script still won't support more than one dsmcad process. But with this option, chances are good that the pid written to the file actually belongs to the process started by the script, so we can actually handle multiple versions of dsmcad running at the same time.

Note that this attachment here is only for the sake of completeness, I still prefer the approach attached in comment #5.
Comment 7 Mads 2012-11-13 09:24:09 UTC
Tested out your A-variant, works fine :)

If you want to support multi dsmcad an idea might be to use pgrep with the -x argument, and testing that against "${command} ${dsmcad-opts}", given multiple conf.d/init.d-files and different dsmcad options.

But I don't know if you ever need that...
Comment 8 Martin von Gagern 2012-11-13 09:34:12 UTC
@Pacho, please commit attachment 329446 [details, diff] as my proxy maintainer, with a revision bump as this is about runtime behaviour.
Comment 9 Pacho Ramos gentoo-dev 2012-12-16 11:41:19 UTC
+*tsm-6.2.2.0-r2 (16 Dec 2012)
+*tsm-6.4.0.0 (16 Dec 2012)
+*tsm-6.3.0.5-r2 (16 Dec 2012)
+
+  16 Dec 2012; Pacho Ramos <pacho@gentoo.org> +files/dsmcad.init.d-r1,
+  +tsm-6.2.2.0-r2.ebuild, +tsm-6.3.0.5-r2.ebuild, +tsm-6.4.0.0.ebuild,
+  -tsm-6.2.2.0-r1.ebuild, -tsm-6.3.0.0-r1.ebuild, -tsm-6.3.0.5-r1.ebuild:
+  Version bump (#446896 by Chris Shelton), also fix licenses (#444412 by Ulrich
+  Müller) and fix init.d script (#442878 by Mads). Thanks to Martin von Gagern
+  for the work. Drop old.
+