On 2023-04-25 14:20, rea...@catastrophe.net wrote:
> On Tue, Apr 25, 2023 at 01:06:35PM -0600, Ashlen wrote:
> >On 2023-04-25 10:45, rea...@catastrophe.net wrote:
> >> After upgrading to 7.3 autossh is failing using the following rc script
> >> in /etc/rc.d/autossh.  It looks like maybe switching to $daemon_user is
> >> not happening to find the correct ssh config stanzas? Thanks in advance
> >> for any help.
> >> 
> >> 
> >> ## Startup configuration
> >> 
> >> #!/bin/ksh
> >> # start autossh tunnel
> >> # requires remoteuser user with $HOME/.ssh/config and keys
> >> 
> >> daemon="/usr/local/bin/autossh"
> >> daemon_flags_1="-M 0 -f -N tun-remoteA"
> >> daemon_flags_1="-M 0 -f -N tun-remoteB"
> >> daemon_user="remoteuser"
> >> 
> >> . /etc/rc.d/rc.subr
> >> 
> >> rc_reload=NO
> >> 
> >> pexp="autossh:.*"
> >> 
> >> # Child will not return a config parsing error to the parent.
> >> rc_start() {
> >>         # use rcexec here since daemon_flags may contain arguments with 
> >> spaces
> >>         ${rcexec} "${daemon} ${daemon_flags_1}" && \
> >>         ${rcexec} "${daemon} ${daemon_flags_1}"
> >> }
> >> 
> >> rc_cmd $1
> >
> >${rcexec} was deprecated in 7.2 and dropped in 7.3. You have to use
> >rc_exec now.
> >
> ># sed -i 's/\${rcexec}/rc_exec/' /etc/rc.d/autossh
> >
> >https://www.openbsd.org/faq/upgrade72.html#ConfigChanges
> >https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/etc/rc.d/rc.subr.diff?r1=1.159&r2=1.160&f=h
> 
> Thanks for that. 
> 
> Even after I modified to use rc_exec I'm still getting the same problem of
> not switching to daemon_user . Comments added inline:
> 
> # rcctl -d start autossh
> doing _rc_parse_conf
> autossh_flags empty, using default ><
> doing rc_check
> autossh
> doing rc_start
> remoteuser
> ^^^^^^^^^^ daemon_user is correctly set to "remoteuser"
> doing _rc_wait_for_start
> doing rc_check
> root            
> ^^^^^^^^^^^^ here is where we should see "remoteuser" and not root when
> ^^^^^^^^^^^^^ running "whoami"
> /etc/rc.d/autossh: /usr/local/bin/autossh -M 0 -f -N tun-remoteA: not found
> doing _rc_rm_runfile
> (failed)
> 
> 
> The modified rc script that yields this output is:
> 
> #!/bin/ksh
> # start autossh tunnel
> # requires remoteuser user with $HOME/.ssh/config and keys
> 
> daemon="/usr/local/bin/autossh"
> daemon_flags_1="-M 0 -f -N rev-tun-lax"
> daemon_flags_2="-M 0 -f -N rev-tun-ord"
> daemon_user="as2h"
> 
> . /etc/rc.d/rc.subr
> 
> rc_reload=NO
> 
> pexp="autossh:.*"
> 
> # Child will not return a config parsing error to the parent.
> rc_start() {
>         # use rc_exec here since daemon_flags may contain arguments with 
> spaces
>       echo ${daemon_user}                             # prove the variable is 
> set here
>       ${rc_exec} "/usr/bin/whoami"    # show who we are running commands as
>     ${rc_exec} "${daemon} ${daemon_flags_1}" && \
>     ${rc_exec} "${daemon} ${daemon_flags_2}"
> }
> 
> rc_cmd $1

rc_exec is a function, not a variable. rc.subr(8) demonstrates how to
use it. This is what I meant for you to do:

rc_start() {
    rc_exec "${daemon} ${daemon_flags_1}" && \
    rc_exec "${daemon} ${daemon_flags_2}"
}

Though, I agree with Stuart. It doesn't make much sense to start two
daemons from one rc.d(8) script.

Reply via email to