Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
not getting correct pidfile in init script (solved)
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
hvengel
Guru
Guru


Joined: 19 Sep 2004
Posts: 515

PostPosted: Sun Jul 10, 2011 11:19 pm    Post subject: not getting correct pidfile in init script (solved) Reply with quote

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
View user's profile Send private message
Sadako
Advocate
Advocate


Joined: 05 Aug 2004
Posts: 3792
Location: sleeping in the bathtub

PostPosted: Sun Jul 10, 2011 11:40 pm    Post subject: Reply with quote

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
View user's profile Send private message
hvengel
Guru
Guru


Joined: 19 Sep 2004
Posts: 515

PostPosted: Mon Jul 11, 2011 3:59 pm    Post subject: Reply with quote

Thanks that was it. I have this working now.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum