Custom script won't start at boot

Hi,

I've created a custom script /usr/local/etc/rc.d/LaBrea.sh in order to enable LaBrea at boot. I have made it executable.

Code:
#!/bin/sh

# $FreeBSD$
#
# PROVIDE: LaBrea
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following line to /etc/rc.conf[.local] to enable LaBrea
#
# LaBrea_enable (bool):	Set to "NO" by default.
#				Set it to "YES" to enable LaBrea.
# LaBrea_user (str):	User account to run with.
# LaBrea_flags (str):	Custom flags for LaBrea.

. /etc/rc.subr

name=LaBrea
rcvar=`set_rcvar`

command="/usr/local/bin/LaBrea -z -s -o -b -p 2000000 -i nfe0"
pidfile="/var/run/${name}.pid"
HOME=$(/usr/sbin/pw usershow -7 -n "${LaBrea_user}" | /usr/bin/cut -d: -f6)

start_cmd="${name}_start"


LaBrea_start()
{
	local pid

	pid=$(check_pidfile $pidfile $command)

	if [ -n "${pid}" ]; then
		echo "${name} already running? (pid=${pid})."
		return 1
	fi

	echo -n "Starting ${name}"
	/usr/bin/touch ${pidfile}
	/usr/sbin/chown ${LaBrea_user} ${pidfile}
	/usr/sbin/daemon -f -p ${pidfile} -u ${LaBrea_user} ${command} 
${LaBrea_flags}
	echo '.'
}

load_rc_config $name

: ${LaBrea_enable="YES"}
: ${LaBrea_user="david"}

run_rc_command "$1"

The script fails during boot with this error -

Code:
Starting LaBrea
usage: chown [-fhvx] [-R [-H | -L | -P]] owner[:group] file ...
       chown [-fhvx] [-R [-H | -L | -P]] :group file ...
daemon: illegal option -- z
usage: daemon [-cf] [-p pidfile] [-u user] command arguments ...

If you can could you please help me sort this out.

Best,

dave
 
It doesn't matter if the user exist it's the variable that's probably empty. I.e. nothing is assigned to it.

Run your script like so:
# sh -x /usr/local/etc/rc.d/LaBrea.sh

That will show you what happens.
 
Ok, This is what I get -

Code:
..............
+ sourced_files=:/etc/rc.conf::/etc/rc.conf.local:
+ [ -r /etc/rc.conf.local ]
+ _rc_conf_loaded=true
+ [ -f /etc/rc.conf.d/LaBrea ]
+ [ -n '' ]
+ eval echo '$LaBrea_enable_defval'
+ echo
+ _defval=''
+ [ -n '' ]
+ : YES
+ run_rc_command ''
+ _return=0
+ rc_arg=''
+ [ -z LaBrea ]
+ shift 1
+ rc_extra_args=''
+ _rc_prefix=''
+ eval '_override_command=$LaBrea_program'
+ _override_command=''
+ command='/usr/local/bin/LaBrea -z -s -o -b -p 2000000 -i nfe0'
+ _keywords='start stop restart rcvar '
+ rc_pid=''
+ _pidcmd=''
+ _procname='/usr/local/bin/LaBrea -z -s -o -b -p 2000000 -i nfe0'
+ [ -n '/usr/local/bin/LaBrea -z -s -o -b -p 2000000 -i nfe0' ]
+ [ -n /var/run/LaBrea.pid ]
+ _pidcmd='rc_pid=$(check_pidfile /var/run/LaBrea.pid /usr/local/bin/LaBrea -z -s -o -b -p 2000000 -i nfe0 )'
+ [ -n 'rc_pid=$(check_pidfile /var/run/LaBrea.pid /usr/local/bin/LaBrea -z -s -o -b -p 2000000 -i nfe0 )' ]
+ _keywords='start stop restart rcvar  status poll'
+ [ -z '' ]
+ rc_usage start stop restart rcvar status poll
+ echo -n 'Usage: /usr/local/etc/rc.d/LaBrea.sh [fast|force|one]('
Usage: /usr/local/etc/rc.d/LaBrea.sh [fast|force|one](+ _sep=''
+ echo -n start
start+ _sep='|'
+ echo -n '|stop'
|stop+ _sep='|'
+ echo -n '|restart'
|restart+ _sep='|'
+ echo -n '|rcvar'
|rcvar+ _sep='|'
+ echo -n '|status'
|status+ _sep='|'
+ echo -n '|poll'
|poll+ _sep='|'
+ echo ')'
)
+ exit 1
grumpy#
 
Add start like you normally would when starting a service.
 
Okay, I start it with -
[cmd=]LaBrea -z -s -o -b -p 2000000 -i nfe0[/cmd]

Now I will add
[cmd=]LaBrea -z -s -o -b -p 2000000 -i nfe0 start[/cmd]

Is it correct?
 
No, I meant adding start as an argument to the rc script.
 
I can now start it after adding

Code:
start_cmd="LaBrea -z -s -o -b -p 2000000 -i nfe0"

But it says -
Code:
pw: no such user `'
 
Move these two to the top of the script:
Code:
: ${LaBrea_enable="YES"}
: ${LaBrea_user="david"}

And change the default to NO.
 
The script starts fine but the boot process stops after initiating the script -

Code:
Initiated on interface nfe0
nfe0: promiscuous mode enabled
Current average bw: 0 (bytes/sec)
Current average bw: 0 (bytes/sec)
42/0 packets (received/dropped) by filter
nfe0: promiscuous mode disabled
Exiting...

I had to stop it in order to get to the desktop. What do I do to get this right.
 
Back
Top