View previous topic :: View next topic |
Author |
Message |
hvengel Guru
Joined: 19 Sep 2004 Posts: 515
|
Posted: Sun Jul 10, 2011 11:19 pm Post subject: not getting correct pidfile in init script (solved) |
|
|
I have a custom init script for setting up a PPS device for ntp. I am trying to improve the script but I have an issue with pidfiles.
If I use the code below I don't get a pidfile.
Code: | !/sbin/runscript
depend() {
need net
use dns logger
after ntp-client
}
start() {
ebegin "Starting custom ntpd"
start-stop-daemon --start --exec /usr/sbin/ldattach --pidfile /var/run/ldattach.pid -- PPS /dev/ttyS1
eend $? "Failed to start ldattach"
sleep 3 # give ldattach and udev time to get settled
/etc/init.d/ntpd start
}
stop() {
ebegin "Stopping custom ntpd"
start-stop-daemon --stop --pidfile /var/run/ldattach.pid
/etc/init.d/ntpd stop
}
|
The start-stop-daemon docs say that when a daemon does not create it's own pidfile I should use --make-pidfile like this:
Code: | start-stop-daemon --start --exec /usr/sbin/ldattach --pidfile /var/run/ldattach.pid --make-pidfile -- PPS /dev/ttyS1 |
Doing that I do get a pidfile but the process number in the pidfile does not match the ldattach process and the stop() command complains about "start-stop-daemon: no matching processes found". It also removes the pidfile but leaves the ldattach process running. How do I set this up so the process-id in the pidfile matches the process I am starting?
Quote: | 19257
/var/run/ldattach.pid lines 1-1/1 (END)
|
Quote: | # ps -A | grep ldatt
19258 ? 00:00:00 ldattach
|
The above show that the actual process-id is 19258 and the pid file has 19257.
Last edited by hvengel on Wed Jul 13, 2011 7:04 pm; edited 1 time in total |
|
Back to top |
|
|
Sadako Advocate
Joined: 05 Aug 2004 Posts: 3792 Location: sleeping in the bathtub
|
Posted: Sun Jul 10, 2011 11:40 pm Post subject: |
|
|
Just checked the man page, ldattach does it's thing and then "goes into the background", my guess is it actually forks a new process that runs in the background.
Try passing -d or --debug to ldattach in your script to keep it in the foreground, and let start-stop-daemon put it into the background instead, ie; Code: | start-stop-daemon --background --start --exec /usr/sbin/ldattach --pidfile /var/run/ldattach.pid -- --debug PPS /dev/ttyS1 |
Ugly, but should work, I've seen the same used before for this kind of problem. _________________ "You have to invite me in" |
|
Back to top |
|
|
hvengel Guru
Joined: 19 Sep 2004 Posts: 515
|
Posted: Mon Jul 11, 2011 3:59 pm Post subject: |
|
|
Thanks that was it. I have this working now. |
|
Back to top |
|
|
|