Stopping services by rc.d scripts

Tomek Wałaszek tmwalaszek at gmail.com
Wed Jan 15 19:06:06 UTC 2014


Hello,
I`ve seen some strange behaviour of the rc scripts when I was stopping
openntpd and opensmtpd. When I was stopping one of those services I saw
this:


[root at shewolf ~]# ptree -C ntpd -l
2690 ntpd: [priv]
  2691 ntpd: ntp engine
    2692 ntpd: dns engine



*[root at shewolf ~]# /usr/local/etc/rc.d/openntpd stopStopping openntpd.kill:
2691: No such processkill: 2692: No such process*

[root at shewolf ~]# uname -a
FreeBSD shewolf.com.pl 9.2-RELEASE-p2 FreeBSD 9.2-RELEASE-p2 #0 r259233:
Thu Dec 12 19:57:26 CET 2013
root at shewolf.com.pl:/usr/obj/usr/src/sys/SHEWOLF
i386


I was wondering why there are those 'No such process' errors.
So in short words what is happening, rc framework will collect all openntpd
pids (openntpd does not support pidfile :( ) and send SIGTERM to them. When
the first process of the openntpd gets SIGTERM it will first kill his
children and quit. So this is the reason why we are seeing 'No such
process'. This problem does not occurs when a daemon supports pid file
becuase rc will get only one pid and send SIGTERM only to it.
It was quite annoying for me so I decided to do something with it. The
simplest solution would be to add pidfile into the
/usr/local/etc/rc.d/openntpd but there is no pidfile in this service. So I
wrote a patch for /etc/rc.subr, you can defined variable *leader* (bool) in
the rc script. If leader will be set to true ("YES" :)) it will kill only
the process group leader, so we will not get any 'No such process' errors
and the process group leader will kill necessary processes. If you will set
it to NO or dont define it in the script it will be running with the
default behaviour.

Maybe there are some other methods to do this but I dont know them.
Patch is in the attachment, I`ve deployed it on my server and everything is
working but anyway be careful ;). If you found it useful thats good but if
you think that my problem is ridiculous and my solution is terrible just
ignore this post ;).


Tomek
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch
Type: application/octet-stream
Size: 2389 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-rc/attachments/20140115/cc0bb6ac/attachment.obj>


More information about the freebsd-rc mailing list