From owner-freebsd-rc@FreeBSD.ORG Thu Apr 12 10:06:03 2012 Return-Path: Delivered-To: freebsd-rc@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 453DD106564A for ; Thu, 12 Apr 2012 10:06:03 +0000 (UTC) (envelope-from turutani@scphys.kyoto-u.ac.jp) Received: from smtp-auth.kuins.kyoto-u.ac.jp (smtp-auth.kuins.kyoto-u.ac.jp [133.3.248.237]) by mx1.freebsd.org (Postfix) with ESMTP id DD05A8FC15 for ; Thu, 12 Apr 2012 10:06:02 +0000 (UTC) Received: from smtp-auth.kuins.kyoto-u.ac.jp (smtp-auth.kuins.kyoto-u.ac.jp [127.0.0.1]) by postfix.imss70 (Postfix) with ESMTP id 40CB32EC00F; Thu, 12 Apr 2012 19:05:56 +0900 (JST) Received: from POLYMER5.scphys.kyoto-u.ac.jp (wd232.BFL23.vectant.ne.jp [210.131.195.232]) by smtp-auth.kuins.kyoto-u.ac.jp (Postfix) with ESMTP id 114B82EC001; Thu, 12 Apr 2012 19:05:56 +0900 (JST) Message-Id: <201204121005.AA01669@POLYMER5.scphys.kyoto-u.ac.jp> From: Tsurutani Naoki Date: Thu, 12 Apr 2012 19:05:55 +0900 To: freebsd-rc@freebsd.org MIME-Version: 1.0 X-Mailer: AL-Mail32 Version 1.13 Content-Type: text/plain; charset=us-ascii Subject: unexpected startup of daemons (Re: conf/166783) X-BeenThere: freebsd-rc@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Discussion related to /etc/rc.d design and implementation." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Apr 2012 10:06:03 -0000 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