Re: after upgrade, can't restart apache via cron

2012-11-26 Thread Mateusz Guzik
On Fri, Nov 23, 2012 at 11:37:54PM +0900, Hiroki Sato wrote:
> "Michael W. Lucas"  wrote
>   in <20121123031753.ga59...@bewilderbeast.blackhelicopters.org>:
> 
> mw> eval: setfib: not found
> mw> /usr/local/etc/rc.d/apache22: WARNING: failed to start apache22
> mw>
> mw> If I run /usr/local/etc/rc.d/apache22 restart from the command line, I
> mw> can restart httpd without trouble.
> mw>
> mw> Any thoughts?
> 
>  This was due to $PATH in the cron job as already pointed out, but
>  this should not happen.  I attached a patch to use full-path for
>  external commands in rc.subr.  If there is no objection to this
>  change I will commit it.
> 

service(8) tries to sanitize stuff before executing scripts. How about
making this the default behaviour?

Currently stuff like PATH "leak" to rc scripts and this can be harmful
(for instance daemon was happily executing stuff from /usr/local/bin,
yet after reboot it stopped working).

Also I doubt anyone relies on current environment and what not to start
a service, but we can provide another target tha would start the service
without sanitizing in case this is needed.

-- 
Mateusz Guzik 
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"


Re: after upgrade, can't restart apache via cron

2012-11-23 Thread Michael W. Lucas
On Thu, Nov 22, 2012 at 09:33:34PM -0600, Adam Vande More wrote:
>I would guess you need*/usr/sbin/ in cron's path.


Thanks everyone.

The real problem here was, I didn't know setfib was a command...

==ml

-- 
Michael W. Lucas
http://www.MichaelWLucas.com/, http://blather.MichaelWLucas.com/
Latest book: SSH Mastery http://www.michaelwlucas.com/nonfiction/ssh-mastery
mwlu...@michaelwlucas.com, Twitter @mwlauthor
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"


Re: after upgrade, can't restart apache via cron

2012-11-23 Thread Hiroki Sato
"Michael W. Lucas"  wrote
  in <20121123031753.ga59...@bewilderbeast.blackhelicopters.org>:

mw> eval: setfib: not found
mw> /usr/local/etc/rc.d/apache22: WARNING: failed to start apache22
mw>
mw> If I run /usr/local/etc/rc.d/apache22 restart from the command line, I
mw> can restart httpd without trouble.
mw>
mw> Any thoughts?

 This was due to $PATH in the cron job as already pointed out, but
 this should not happen.  I attached a patch to use full-path for
 external commands in rc.subr.  If there is no objection to this
 change I will commit it.

-- Hiroki
Index: etc/rc.subr
===
--- etc/rc.subr	(revision 243327)
+++ etc/rc.subr	(working copy)
@@ -49,6 +49,18 @@
 IDCMD="if [ -x $ID ]; then $ID -un; fi"
 PS="/bin/ps -ww"
 JID=`$PS -p $$ -o jid=`
+CHROOT_CMD="/usr/sbin/chroot"
+DEVFS_CMD="/sbin/devfs"
+EGREP_CMD="/usr/bin/egrep"
+GREP_CMD="/usr/bin/grep"
+KLDSTAT_CMD="/sbin/kldstat"
+KLDLOAD_CMD="/sbin/kldload"
+LOGGER_CMD="/usr/bin/logger"
+MDMFS_CMD="/sbin/mdmfs"
+MOUNT_CMD="/sbin/mount"
+NICE_CMD="/usr/bin/nice"
+SETFIB_CMD="/usr/sbin/setfib"
+SU_CMD="/usr/bin/su"

 #
 #	functions
@@ -181,7 +193,7 @@
 			if $_ismounted; then
 :
 			else
-mount $_fs >/dev/null 2>&1
+${MOUNT_CMD} $_fs >/dev/null 2>&1
 			fi
 		)
 	done
@@ -726,17 +738,17 @@
 			check_startmsgs && echo "Starting ${name}."
 			if [ -n "$_chroot" ]; then
 _doit="\
-${_nice:+nice -n $_nice }\
-${_fib:+setfib -F $_fib }\
-chroot ${_user:+-u $_user }${_group:+-g $_group }${_groups:+-G $_groups }\
+${_nice:+${NICE_CMD} -n $_nice }\
+${_fib:+${SETFIB_CMD} -F $_fib }\
+${CHROOT_CMD} ${_user:+-u $_user }${_group:+-g $_group }${_groups:+-G $_groups }\
 $_chroot $command $rc_flags $command_args"
 			else
 _doit="\
 ${_chdir:+cd $_chdir && }\
-${_fib:+setfib -F $_fib }\
+${_fib:+${SETFIB_CMD} -F $_fib }\
 $command $rc_flags $command_args"
 if [ -n "$_user" ]; then
-_doit="su -m $_user -c 'sh -c \"$_doit\"'"
+_doit="${SU_CMD} -m $_user -c 'sh -c \"$_doit\"'"
 fi
 if [ -n "$_nice" ]; then
 	if [ -z "$_user" ]; then
@@ -953,7 +965,7 @@

 	_cmd="kill -$1 $rc_pid"
 	if [ -n "$_user" ]; then
-		_cmd="su -m ${_user} -c 'sh -c \"${_cmd}\"'"
+		_cmd="${SU_CMD} -m ${_user} -c 'sh -c \"${_cmd}\"'"
 	fi
 	echo "$_cmd"
 }
@@ -1110,8 +1122,8 @@
 	exitval=$1
 	shift

-	if [ -x /usr/bin/logger ]; then
-		logger "$0: ERROR: $*"
+	if [ -x ${LOGGER_CMD} ]; then
+		${LOGGER_CMD} "$0: ERROR: $*"
 	fi
 	echo 1>&2 "$0: ERROR: $*"
 	exit $exitval
@@ -1123,8 +1135,8 @@
 #
 warn()
 {
-	if [ -x /usr/bin/logger ]; then
-		logger "$0: WARNING: $*"
+	if [ -x ${LOGGER_CMD} ]; then
+		${LOGGER_CMD} "$0: WARNING: $*"
 	fi
 	echo 1>&2 "$0: WARNING: $*"
 }
@@ -1137,8 +1149,8 @@
 {
 	case ${rc_info} in
 	[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
-		if [ -x /usr/bin/logger ]; then
-			logger "$0: INFO: $*"
+		if [ -x ${LOGGER_CMD} ]; then
+			${LOGGER_CMD} "$0: INFO: $*"
 		fi
 		echo "$0: INFO: $*"
 		;;
@@ -1155,8 +1167,8 @@
 {
 	case ${rc_debug} in
 	[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
-		if [ -x /usr/bin/logger ]; then
-			logger "$0: DEBUG: $*"
+		if [ -x ${LOGGER_CMD} ]; then
+			${LOGGER_CMD} "$0: DEBUG: $*"
 		fi
 		echo 1>&2 "$0: DEBUG: $*"
 		;;
@@ -1320,7 +1332,7 @@
 			fi
 			eval $rulename=\$rulenum
 			debug "found ruleset: $rulename=$rulenum"
-			if ! /sbin/devfs rule -s $rulenum delset; then
+			if ! ${DEVFS_CMD} rule -s $rulenum delset; then
 _err=1
 break
 			fi
@@ -1331,7 +1343,7 @@
 			# other rules
 			if [ -n "$rulecmd" ]; then
 debug "adding rule ($rulecmd)"
-if ! eval /sbin/devfs rule -s $rulenum $rulecmd
+if ! eval ${DEVFS_CMD} rule -s $rulenum $rulecmd
 then
 	_err=1
 	break
@@ -1389,7 +1401,7 @@
 		return 1
 	fi
 	debug "$_me: setting ruleset ($rs) on mount-point (${devdir#-m })"
-	if ! /sbin/devfs $devdir ruleset $rs; then
+	if ! ${DEVFS_CMD} $devdir ruleset $rs; then
 		warn "$_me: unable to set ruleset $rs to ${devdir#-m }"
 		return 1
 	fi
@@ -1414,7 +1426,7 @@
 		return 1
 	fi
 	debug "$_me: applying ruleset ($rs) to mount-point (${devdir#-m })"
-	if ! /sbin/devfs $devdir rule -s $rs applyset; then
+	if ! ${DEVFS_CMD} $devdir rule -s $rs applyset; then
 		warn "$_me: unable to apply ruleset $rs to ${devdir#-m }"
 		return 1
 	fi
@@ -1438,14 +1450,14 @@
 		return 1
 	fi
 	debug "$_me: mount-point is ($devdir), ruleset is ($rs)"
-	if ! mount -t devfs dev "$devdir"; then
+	if ! ${MOUNT_CMD} -t devfs dev "$devdir"; then
 		warn "$_me: Unable to mount devfs on $devdir"
 		return 1
 	fi
 	if [ -n "$rs" ]; then
 		devfs_init_rulesets
 		devfs_set_ruleset $rs $devdir
-		devfs -m $devdir rule applyset
+		${DEVFS_CMD} -m $devdir rule applyset
 	fi
 	return 0
 }
@@ -1483,7 +1495,7 @@
 	if [ -n "$3" ]; then
 		flags="$3"
 	fi
-	/sbin/mdmfs $flags -s $1 md $2
+	${MDMFS_CMD} $flags -s $1 md $2
 }

 # Code common to scripts that need to load a kernel module
@@ -1512,16 +1524,16 @@
 	_mod=${_mod:-$1}
 	_loaded=false
 	if 

Re: after upgrade, can't restart apache via cron

2012-11-23 Thread Mateusz Guzik
On Thu, Nov 22, 2012 at 10:17:54PM -0500, Michael W. Lucas wrote:
> 
> 
> FreeBSD bewilderbeast.blackhelicopters.org 10.0-CURRENT FreeBSD 10.0-CURRENT 
> #15: Thu Nov  8 14:02:45 EST 2012 
> mwlu...@bewilderbeast.blackhelicopters.org:/usr/obj/usr/src/sys/GENERIC  amd64
> 
> I can manually restart apache22 with the following /etc/rc.conf entries:
> 
> apache22_enable="YES"
> apache22_fib=0
> 
> I have a cron entry that restarts apache regularly, to compensate for
> some mysql daftness.
> 
> 13  *  * * * /usr/local/etc/rc.d/apache22 restart
> 
> When this job runs, I get the following email:
> 
[..]
> eval: setfib: not found
[..]
> 
> If I run /usr/local/etc/rc.d/apache22 restart from the command line, I
> can restart httpd without trouble.
> 

As others pointers out already it is a PATH issue, but I don't think
that restoring /usr/sbin in PATH is the answer here.

You should be using service(8) script since it does The Right Thing(tm).
Apache will be started in more-or-less same environment that was used
during boot time. (My personal opinion is that startup scripts should
prepare such environment on their own unless explicitly told otherwise,
and by environment I mean more that 'environment' variables.)

If this is a bug or not I cannot say. /etc/rc.subr contains lines like:
SYSCTL="/sbin/sysctl"
ID="/usr/bin/id"

for few tools, rest is assumed to work with provided PATH.

To sum up, use service(8) and you will be fine.

-- 
Mateusz Guzik 
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"


Re: after upgrade, can't restart apache via cron

2012-11-22 Thread Freddie Cash
The interrupted unix faq, a wonderful thing.  :) Covers this exactly. :)

http://www.wonkity.com/~wblock/docs/html/interrupted.html
On Nov 22, 2012 7:28 PM, "Michael W. Lucas" 
wrote:

>
>
> FreeBSD bewilderbeast.blackhelicopters.org 10.0-CURRENT FreeBSD
> 10.0-CURRENT #15: Thu Nov  8 14:02:45 EST 2012
> mwlu...@bewilderbeast.blackhelicopters.org:/usr/obj/usr/src/sys/GENERIC
>  amd64
>
> I can manually restart apache22 with the following /etc/rc.conf entries:
>
> apache22_enable="YES"
> apache22_fib=0
>
> I have a cron entry that restarts apache regularly, to compensate for
> some mysql daftness.
>
> 13  *  * * * /usr/local/etc/rc.d/apache22 restart
>
> When this job runs, I get the following email:
>
> Performing sanity check on apache22 configuration:
> Syntax OK
> Stopping apache22.
> Waiting for PIDS: 59501.
> Performing sanity check on apache22 configuration:
> Syntax OK
> Starting apache22.
> eval: setfib: not found
> /usr/local/etc/rc.d/apache22: WARNING: failed to start apache22
>
> If I run /usr/local/etc/rc.d/apache22 restart from the command line, I
> can restart httpd without trouble.
>
> Any thoughts?
>
> ==ml
>
> --
> Michael W. Lucas
> http://www.MichaelWLucas.com/, http://blather.MichaelWLucas.com/
> Latest book: SSH Mastery
> http://www.michaelwlucas.com/nonfiction/ssh-mastery
> mwlu...@michaelwlucas.com, Twitter @mwlauthor
> ___
> freebsd-current@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"
>
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"


Re: after upgrade, can't restart apache via cron

2012-11-22 Thread Adam McDougall

On 11/22/2012 10:17 PM, Michael W. Lucas wrote:


FreeBSD bewilderbeast.blackhelicopters.org 10.0-CURRENT FreeBSD 10.0-CURRENT 
#15: Thu Nov  8 14:02:45 EST 2012 
mwlu...@bewilderbeast.blackhelicopters.org:/usr/obj/usr/src/sys/GENERIC  amd64

I can manually restart apache22 with the following /etc/rc.conf entries:

apache22_enable="YES"
apache22_fib=0

I have a cron entry that restarts apache regularly, to compensate for
some mysql daftness.

13  *  * * * /usr/local/etc/rc.d/apache22 restart

When this job runs, I get the following email:

Performing sanity check on apache22 configuration:
Syntax OK
Stopping apache22.
Waiting for PIDS: 59501.
Performing sanity check on apache22 configuration:
Syntax OK
Starting apache22.
eval: setfib: not found
/usr/local/etc/rc.d/apache22: WARNING: failed to start apache22

If I run /usr/local/etc/rc.d/apache22 restart from the command line, I
can restart httpd without trouble.

Any thoughts?

==ml


Make sure the path to setfib is in PATH in the crontab?

PATH=/blah/blah/blah:/usr/sbin
* *   *   *   *   blah

___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"


Re: after upgrade, can't restart apache via cron

2012-11-22 Thread Adam Vande More
On Thu, Nov 22, 2012 at 9:17 PM, Michael W. Lucas  wrote:

>
>
> FreeBSD bewilderbeast.blackhelicopters.org 10.0-CURRENT FreeBSD
> 10.0-CURRENT #15: Thu Nov  8 14:02:45 EST 2012
> mwlu...@bewilderbeast.blackhelicopters.org:/usr/obj/usr/src/sys/GENERIC
>  amd64
>
> I can manually restart apache22 with the following /etc/rc.conf entries:
>
> apache22_enable="YES"
> apache22_fib=0
>
> I have a cron entry that restarts apache regularly, to compensate for
> some mysql daftness.
>
> 13  *  * * * /usr/local/etc/rc.d/apache22 restart
>
> When this job runs, I get the following email:
>
> Performing sanity check on apache22 configuration:
> Syntax OK
> Stopping apache22.
> Waiting for PIDS: 59501.
> Performing sanity check on apache22 configuration:
> Syntax OK
> Starting apache22.
> eval: setfib: not found
> /usr/local/etc/rc.d/apache22: WARNING: failed to start apache22
>
> If I run /usr/local/etc/rc.d/apache22 restart from the command line, I
> can restart httpd without trouble.
>
> Any thoughts?
>

I would guess you need /usr/sbin/ in cron's path.

-- 
Adam Vande More
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"


Re: after upgrade, can't restart apache via cron

2012-11-22 Thread David Wolfskill
On Thu, Nov 22, 2012 at 10:17:54PM -0500, Michael W. Lucas wrote:
> ... 
> 13  *  * * * /usr/local/etc/rc.d/apache22 restart
> 
> When this job runs, I get the following email:
> 
> Performing sanity check on apache22 configuration:
> ...
> eval: setfib: not found
> /usr/local/etc/rc.d/apache22: WARNING: failed to start apache22
> 
> If I run /usr/local/etc/rc.d/apache22 restart from the command line, I
> can restart httpd without trouble.
> 
> Any thoughts?

PATH used by cron -- per crontab(5):

 Several environment variables are set up automatically by the cron(8)
 daemon.  SHELL is set to /bin/sh, PATH is set to /usr/bin:/bin, and
 LOGNAME and HOME are set from the /etc/passwd line of the crontab's
 owner.  HOME, PATH and SHELL may be overridden by settings in the
 crontab; LOGNAME may not.

and setfib is:

g1-227(9.1-P)[1] which setfib
/usr/sbin/setfib
g1-227(9.1-P)[2] 

Looks as if overriding PATH (in crontab) is least disruptive change
that will work.

Peace,
david
-- 
David H. Wolfskill  da...@catwhisker.org
Taliban: Evil men with guns afraid of truth from a 14-year old girl.

See http://www.catwhisker.org/~david/publickey.gpg for my public key.


pgpH9ZXUDoVFm.pgp
Description: PGP signature


after upgrade, can't restart apache via cron

2012-11-22 Thread Michael W. Lucas


FreeBSD bewilderbeast.blackhelicopters.org 10.0-CURRENT FreeBSD 10.0-CURRENT 
#15: Thu Nov  8 14:02:45 EST 2012 
mwlu...@bewilderbeast.blackhelicopters.org:/usr/obj/usr/src/sys/GENERIC  amd64

I can manually restart apache22 with the following /etc/rc.conf entries:

apache22_enable="YES"
apache22_fib=0

I have a cron entry that restarts apache regularly, to compensate for
some mysql daftness.

13  *  * * * /usr/local/etc/rc.d/apache22 restart

When this job runs, I get the following email:

Performing sanity check on apache22 configuration:
Syntax OK
Stopping apache22.
Waiting for PIDS: 59501.
Performing sanity check on apache22 configuration:
Syntax OK
Starting apache22.
eval: setfib: not found
/usr/local/etc/rc.d/apache22: WARNING: failed to start apache22

If I run /usr/local/etc/rc.d/apache22 restart from the command line, I
can restart httpd without trouble.

Any thoughts?

==ml

-- 
Michael W. Lucas
http://www.MichaelWLucas.com/, http://blather.MichaelWLucas.com/
Latest book: SSH Mastery http://www.michaelwlucas.com/nonfiction/ssh-mastery
mwlu...@michaelwlucas.com, Twitter @mwlauthor
___
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"