# rc script:start_precmd ignored



## free-and-bsd (Oct 20, 2017)

Hi everyone.

I've installed FreeRADIUS, but it has one small thing about it which causes unexpected complications. It requires (by OpenSSL) tmpdir=/tmp/radiusd to exist for the server to start. Wouldn't be a problem, but I've set clear_tmp_enable="YES" in my /etc/rc.conf, which leaves /tmp clean upon reboot.

No problem, /tmp/radiusd can be created manually without even special permissions... But in order to enable _automatic_ daemon startup on boot I've used the rc.subr(8) variable start_precmd as a recommended way to add extra actions to the rc startup script:

```
#blablabla
. /etc/rc.subr

name=radiusd
rcvar=radiusd_enable
load_rc_config $name

command=/usr/local/sbin/radiusd

extra_commands="reload debug"
debug_cmd="radiusd_debug"
required_dirs=`echo ${radiusd_flags} | sed -Ene 's:.*\-[^[:space:]d]*d[[:space:]]*([^[:space
:]]+).*:\1:p'`
required_dirs=${required_dirs:-"/usr/local/etc/raddb"}
required_files="${required_dirs}/radiusd.conf"
radiusd_enable=${radiusd_enable-"NO"}
command_args="&"
[B]start_precmd="${radiusd_prestart}"[/B]

radiusd_debug()
{
    radiusd_flags="-X ${radiusd_flags}"
    run_rc_command start
}

[B]radiusd_prestart()
{
   if [ ! -d /tmp/radiusd ]; then
      /bin/mkdir /tmp/radiusd
   fi
}[/B]

run_rc_command "$1"
```
 My unsophisticated *custom code* here works fine when invoked by ordinary user (me) and  successfully creates /tmp/radiusd, but from the startup script it doesn't create anything. What might be the problem here? One doesnt' need any special permissions to create things in the /tmp dir, and startup scripts are run by root, are they not?


----------



## tobik@ (Oct 21, 2017)

free-and-bsd said:


> *start_precmd="${radiusd_prestart}"*


This should be start_precmd="radiusd_prestart"


----------



## free-and-bsd (Oct 21, 2017)

tobik@ said:


> This should be start_precmd="radiusd_prestart"


Of course , thank you!! Obviously, working too late at night is no use...


----------



## free-and-bsd (Oct 23, 2017)

free-and-bsd said:


> ...  I've used the rc.subr(8) variable start_precmd as a *recommended* way to add extra actions to the rc startup script...


It would be more proper to say: the _only _way one can do this successfully. But I was a bit disappointed by the way manual pages handle this matter. 

I mean, here is the only mentioning of it in rc.subr(8):


> *argument_precmd*
> Shell commands to run just before running
> *argument_cmd* or the default method for
> argument.  If this returns a non-zero exit
> ...




I'm by no means new to manual reading, but "_shell commands_ to run just before..." doesn't make it immediately clear to me that those are CUSTOM _shell commands_ sysadmin or porter feels necessary to add to a startup script for some actions that go beyond the capabilities of rc.subr(8) stuff (the stuff that makes the main subject of the man page). 

Yes, I know the logic "if you don't know what it is, then more likely than not you don't need this stuff". But one needs to be balanced about it, too, or else we'll end up with the "insider" approach: we know what we're talking about; you don't, so you're not one of us... 
It seems to me, then, that some appropriate explicitness _might_ be added to the part of the manual page that deals with what goes "beyond" the standard routines. Some explicit introduction like: "_In some situations additional actions may be required in order to start a daemon_. Use *argument_precmd* for such shell commands that must be run just before..." Short, but clear enough to attract one's attention.

As to my OP, we can mark this as SOLVED.​


----------



## tobik@ (Oct 23, 2017)

free-and-bsd said:


> It would be more proper to say: the _only _way one can do this successfully. But I was a bit disappointed by the way manual pages handle this matter.


Documentation problems or vagueness are valid bugs so open one on https://bugs.freebsd.org !


----------

