Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 Apr 2012 19:05:55 +0900
From:      Tsurutani Naoki <turutani@scphys.kyoto-u.ac.jp>
To:        freebsd-rc@freebsd.org
Subject:   unexpected startup of daemons (Re: conf/166783)
Message-ID:  <201204121005.AA01669@POLYMER5.scphys.kyoto-u.ac.jp>

next in thread | raw e-mail | index | archive | help
Hi all,

 I have a question about startup behaviour of daemons:
Some rc scripts run unexpectedly.

  I installed ports/net-mgmt/mrtg and I use the startup script copied from
the one installed by this port, in order to change the order to run.
I named the script and variables with "my_" prefix and enable them;
original script exists and disabled in rc.conf.  In my script
I did not change the PID filename.

  While booting the FreeBSD, "my_mrtg_daemon" script runs fine,
and original "mrtg_daemon" script also runs unexpectedly and dies,
for PID file is not writable.  Original pid file made by "my_mrtg_daemon"
is removed at that time, for the user and group for mrtg are changed
only for *my* script.  When the user and group are the same,
two mrtg daemons run. 

  I think "XXX_enable" variable controls whether the program pointed
in the script should run or not; however, disabled script can run
with normal "start" option.  But, in this case, when I execute a script,
first, the PID file is checked even if the script is not enabled by rc.conf.
If the PID file exists and the process shown in PID file also exists,
script returns message like "the process still exists"; normal "start" arugument.
However, if it is executed with "faststart" argument (like in booting sequence),
PID file is removed and the program is executed.  In both case, scripts
that are not enabled by rc.conf are executed, and the variables except "XXX_enable"
are used unexpectedly.  If two or more scripts use the same PID file and
the only one of them is enabled by rc.conf, and when they have same "program",
such as some interpreter language especially, unexpected programs can be executed.

  I think scripts without "XXX_enable=YES" should not run, even if
the PID file exists; otherwise, we should take care of the variables
which are not enabled.  In addition, some bugs exist that execute
the "start" routine of disabled scripts.
Isn't my idea is wrong ?

diff of original startup script and "my_" script:
--- mrtg_daemon	2012-04-09 12:19:22.000000000 +0900
+++ my_mrtg_daemon	2012-04-11 10:31:47.000000000 +0900
@@ -2,36 +2,37 @@
 #
 # $FreeBSD: ports/net-mgmt/mrtg/files/mrtg_daemon.in,v 1.4 2012/01/14 08:56:37 dougb Exp $
 
+# Copied from mrtg_daemon, to control order. Tsurutani Naoki.
 #
-# PROVIDE: mrtg_daemon
+# PROVIDE: my_mrtg_daemon
 # REQUIRE: DAEMON bsnmpd snmpd
 # KEYWORD: shutdown
 
 . /etc/rc.subr
 
 
-name="mrtg_daemon"
-rcvar=mrtg_daemon_enable
+name="my_mrtg_daemon"
+rcvar=my_mrtg_daemon_enable
 
 load_rc_config $name
 
-: ${mrtg_daemon_enable="NO"}
-: ${mrtg_daemon_pidfile="/var/run/mrtg/mrtg.pid"}
-: ${mrtg_daemon_user="mrtg"}
-: ${mrtg_daemon_group="mrtg"}
-: ${mrtg_daemon_config="/usr/local/etc/mrtg/mrtg.cfg"}
+: ${my_mrtg_daemon_enable="NO"}
+: ${my_mrtg_daemon_pidfile="/var/run/mrtg/mrtg.pid"}
+: ${my_mrtg_daemon_user="mrtg"}
+: ${my_mrtg_daemon_group="mrtg"}
+: ${my_mrtg_daemon_config="/usr/local/etc/mrtg/mrtg.cfg"}
 
-: ${mrtg_daemon_flags="--pid-file $mrtg_daemon_pidfile --lock-file /var/run/mrtg/lockfile 
--confcache-file /var/run/mrtg/confcache --user $mrtg_daemon_user --group 
$mrtg_daemon_group --daemon $mrtg_daemon_config"}
+: ${my_mrtg_daemon_flags="--pid-file $my_mrtg_daemon_pidfile --lock-file 
/var/run/mrtg/lockfile --confcache-file /var/run/mrtg/confcache --user $my_mrtg_daemon_user 
--group $my_mrtg_daemon_group --daemon $my_mrtg_daemon_config"}
 
-start_precmd="mrtg_daemon_precmd"
+start_precmd="my_mrtg_daemon_precmd"
 
 command="/usr/local/bin/mrtg"
 command_interpreter="/usr/local/bin/perl"
-pidfile=${mrtg_daemon_pidfile}
+pidfile=${my_mrtg_daemon_pidfile}
 
-mrtg_daemon_precmd()
+my_mrtg_daemon_precmd()
 {
-       rm -f /var/run/mrtg/lockfile /var/run/mrtg/confcache $mrtg_daemon_pidfile
+       rm -f /var/run/mrtg/lockfile /var/run/mrtg/confcache $my_mrtg_daemon_pidfile
        export LANG=C
 }
 
===== End of Diff =====

my rc.conf file about mrtg:
mrtg_daemon_enable="NO"
mrtg_daemon_pidfile="/var/run/mrtg/mrtg.pid"
mrtg_daemon_user="mrtg"
mrtg_daemon_group="mrtg"
mrtg_daemon_config="/usr/local/etc/mrtg/mrtg.cfg"
my_mrtg_daemon_enable="YES"
my_mrtg_daemon_pidfile="/var/run/mrtg/mrtg.pid"
my_mrtg_daemon_user="www"
my_mrtg_daemon_group="www"
my_mrtg_daemon_config="/usr/local/etc/mrtg/mrtg.cfg"
my_mrtg_daemon_others_enable="NO"
my_mrtg_daemon_others_pidfile="/var/run/mrtg/others.pid"
my_mrtg_daemon_others_user="mrtg"
my_mrtg_daemon_others_group="mrtg"
my_mrtg_daemon_others_config="/usr/local/etc/mrtg/others.cfg"

===== End of rc.conf =====

console.log with booting rc_debug=1 and rc_info=1 in /etc/rc.conf is available at
http://barutan.s296.xrea.com/nocache/bootlog20120411.txt


--- 
Tsurutani Naoki
turutani@scphys.kyoto-u.ac.jp



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201204121005.AA01669>