From rand@meridian-enviro.com  Fri Dec  9 23:41:48 2005
Return-Path: <rand@meridian-enviro.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 5DCDF16A467
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  9 Dec 2005 23:41:41 +0000 (GMT)
	(envelope-from rand@meridian-enviro.com)
Received: from newman.meridian-enviro.com (newman.meridian-enviro.com [207.109.235.166])
	by mx1.FreeBSD.org (Postfix) with ESMTP id D51AC43DE0
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  9 Dec 2005 23:41:14 +0000 (GMT)
	(envelope-from rand@meridian-enviro.com)
Received: from clavin.meridian-enviro.com (dhcp-207.meridian-enviro.com [10.10.10.207])
	by newman.meridian-enviro.com (8.13.1/8.13.1) with ESMTP id jB9Nf30a083844
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 9 Dec 2005 17:41:03 -0600 (CST)
	(envelope-from rand@meridian-enviro.com)
Received: (from rand@localhost)
	by clavin.meridian-enviro.com (8.13.4/8.13.4/Submit) id jB9Nf3uc025999;
	Fri, 9 Dec 2005 17:41:03 -0600 (CST)
	(envelope-from rand)
Message-Id: <200512092341.jB9Nf3uc025999@clavin.meridian-enviro.com>
Date: Fri, 9 Dec 2005 17:41:03 -0600 (CST)
From: "Douglas K. Rand" <rand@meridian-enviro.com>
Reply-To: "Douglas K. Rand" <rand@meridian-enviro.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: Easily launch non-forking daemons like logsurfer via rcNG
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         90163
>Category:       conf
>Synopsis:       [patch] Easily launch non-forking daemons like logsurfer via rcNG
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    dougb
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Dec 09 23:50:02 GMT 2005
>Closed-Date:    Tue Dec 29 07:27:22 UTC 2009
>Last-Modified:  Tue Dec 29 07:27:22 UTC 2009
>Originator:     Douglas K. Rand
>Release:        FreeBSD 6.0-STABLE i386
>Organization:
Meridian Envrionmental Technology, Inc.
>Environment:
System: FreeBSD clavin.meridian-enviro.com 6.0-STABLE FreeBSD 6.0-STABLE #0: Fri Nov 25 10:15:22 CST 2005 root@cliff.meridian-enviro.com:/usr/obj/usr/src/sys/CLIFF i386


	
>Description:
	While trying to make a nice rcNG script for the logsurfer port, I
	found it useful to add "daemon ..." to the command line like "nice ..."
	is. The problem is that logsurfer doesn't become a demon on its own
	when you run it. You can "fake" this by setting logsurfer_command
	to "daemon" and prepending "/usr/local/sbin/logsurfer" to logsurfer_flags,
	but that seemd like a hack.
	
>How-To-Repeat:
	Try to write a nice rcNG script for logsurfer.
>Fix:
	Here's a patch that adds daemon to the command line in rc.subr:


--- rc.subr.orig	Fri Dec  9 14:11:58 2005
+++ rc.subr	Fri Dec  9 17:29:39 2005
@@ -370,6 +370,8 @@
 #
 #	${name}_nice	n	Nice level to run ${command} at.
 #
+#	${name}_daemon	n	Should we run ${command} under /usr/sbin/daemon?
+#
 #	${name}_user	n	User to run ${command} as, using su(1) if not
 #				using ${name}_chroot.
 #				Requires /usr to be mounted.
@@ -525,7 +527,8 @@
 	fi
 	eval _chdir=\$${name}_chdir	_chroot=\$${name}_chroot \
 	    _nice=\$${name}_nice	_user=\$${name}_user \
-	    _group=\$${name}_group	_groups=\$${name}_groups
+	    _group=\$${name}_group	_groups=\$${name}_groups \
+	    _daemon=\$${name}_daemon
 
 	if [ -n "$_user" ]; then	# unset $_user if running as that user
 		if [ "$_user" = "$(eval $IDCMD)" ]; then
@@ -651,12 +654,14 @@
 			if [ -n "$_chroot" ]; then
 				_doit="\
 ${_nice:+nice -n $_nice }\
+${_daemon:+daemon }\
 chroot ${_user:+-u $_user }${_group:+-g $_group }${_groups:+-G $_groups }\
 $_chroot $command $rc_flags $command_args"
 			else
 				_doit="\
 ${_chdir:+cd $_chdir; }\
 ${_nice:+nice -n $_nice }\
+${_daemon:+daemon }\
 $command $rc_flags $command_args"
 				if [ -n "$_user" ]; then
 				    _doit="su -m $_user -c 'sh -c \"$_doit\"'"


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-rc 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Wed Jan 18 07:44:04 UTC 2006 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=90163 
State-Changed-From-To: open->closed 
State-Changed-By: dougb 
State-Changed-When: Wed Jan 18 07:56:14 UTC 2006 
State-Changed-Why:  

The way to do what you are suggesting here is: 

command=/usr/sbin/daemon 
command_args="/usr/local/sbin/logsurfer $logsurfer_flags" 

While the idea you present here is creative, I don't think 
that it happens often enough in practice to warrant inclusion 
in rc.subr.  

In the future, you may find it useful to submit ideas like 
this to the freebsd-rc@freebsd.org mailling list before 
sending them as a PR.  

Doug 



Responsible-Changed-From-To: freebsd-rc->dougb 
Responsible-Changed-By: dougb 
Responsible-Changed-When: Wed Jan 18 07:56:14 UTC 2006 
Responsible-Changed-Why:  

I closed this PR. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=90163 
State-Changed-From-To: closed->analyzed 
State-Changed-By: dougb 
State-Changed-When: Wed Jan 18 08:08:24 UTC 2006 
State-Changed-Why:  

Turns out I was too hasty, and what I suggested won't work. 
Let me think about this for a bit ... 

http://www.freebsd.org/cgi/query-pr.cgi?pr=90163 
State-Changed-From-To: analyzed->closed 
State-Changed-By: dougb 
State-Changed-When: Tue Dec 29 07:24:42 UTC 2009 
State-Changed-Why:  

There are reasonable ways to solve this problem, the most 
common currently being 'command_args="&"'. 

The other problem with this suggestion is that /usr may 
not be mounted at start time. 

So, this time close it for real (belatedly). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=90163 
>Unformatted:
