Why isn't chdir happening for this rc.d script?

640 views Asked by At

I've hit a wall trying to understand why the ${name}_chdir variable is not working for me. Finally, after letting my script run with -xv, I see that the cd command is not even being run in my case. Here is my script:

#!/bin/sh
set -xv
exec 1>/tmp/awning.rclog 2>&1

# REQUIRE: NETWORKING LOGIN DAEMON
# KEYWORD: shutdown

. /etc/rc.subr

name="awning"
rcvar="awning_enable"
awning_chdir="/usr/sbin/awning"

pidfile="/var/run/awningd.pid"
procname="daemon"

# -f flag is to redirect stdin/stdout/stderr to /dev/null to prevent node from crashing
# on system-startup
start_cmd="/usr/sbin/daemon -r -P ${pidfile} -f -u pierre /usr/sbin/awning/intro.js"
command="/usr/sbin/daemon -r -P ${pidfile} -f -u pierre /usr/sbin/awning/intro.js"
load_rc_config $name
run_rc_command "$1"

At first I was only using start_cmd, but then I read in rc.subr the following:

${name}_chdir

        Directory to cd to before running _command_, if
        ${name}_chroot is not provided.

so I thought maybe things were getting mixed up, so i added the command=.... bit, and removed the start_cmd=.... line, and still no success. Here's the relevant "doit" portion of the output which was saved from running the script with -xv:

+ _chdir=/usr/sbin/awning _chroot='' _nice='' _user='' _group='' _groups='' _fib='' _env='' _prepend='' _login_class=daemon _oomprotect=''
+ [ -n '' ]
+ [ -z yes ]
+ [ start '!=' start ]
+ [ -n awning_enable -a start '!=' rcvar -a start '!=' stop -a start '!=' describe ]
+ checkyesno awning_enable
+ eval '_value=$awning_enable'
+ _value=YES
+ debug 'checkyesno: awning_enable is set to YES.'
+ return 0
+ [ start '=' start -a -z yes -a -n '' ]
+ eval '_cmd=$start_cmd' '_precmd=$start_precmd' '_postcmd=$start_postcmd'
+ _cmd='/usr/sbin/daemon -r -P /var/run/awningd.pid -f -u pierre /usr/sbin/awning/intro.js' _precmd='' _postcmd=''
+ [ -n '/usr/sbin/daemon -r -P /var/run/awningd.pid -f -u pierre /usr/sbin/awning/intro.js' ]
+ _run_rc_precmd
+ check_required_before start
+ local _f
+ return 0
+ [ -n '' ]
+ check_required_after start
+ local _f _args
+ return 0
+ return 0
+ _run_rc_doit '/usr/sbin/daemon -r -P /var/run/awningd.pid -f -u pierre /usr/sbin/awning/intro.js '
+ debug 'run_rc_command: doit: /usr/sbin/daemon -r -P /var/run/awningd.pid -f -u pierre /usr/sbin/awning/intro.js '
+ eval '/usr/sbin/daemon -r -P /var/run/awningd.pid -f -u pierre /usr/sbin/awning/intro.js '
+ /usr/sbin/daemon -r -P /var/run/awningd.pid -f -u pierre /usr/sbin/awning/intro.js
+ _return=0
+ [ 0 -ne 0 ]
+ return 0
+ _run_rc_postcmd
+ [ -n '' ]
+ return 0
+ return 0

_chdir is being set properly, but it's never used for anything. Honestly it looks like those variables (_chdir, _chroot, etc) should actually be awning_chdir, awning_chroot, etc...

What could be going on?

I'm running version 11.0-RELEASE-p2

1

There are 1 answers

0
papiro On BEST ANSWER

After stepping through /etc/rc.subr, I learned (the hard way) that command= needs to literally be a single command. There's a test done on it ([ ! -x $command ]) which fails even for a command with options and no arguments. I had to split apart the options I was passing daemon, and its single argument /usr/sbin/awning/intro.js into a separate variable: command_args=, which solved the issue.