Problem with openrc script for dnscrypt-proxy


#1

Hi,
I installed the dnscrypt-proxy package.
But now I’m trying to get it to start at boot with a openrc script. And it fails…
This is the script (I actualy copied the openntpd script and modified it) in /usr/local/etc/init.d :

#!/sbin/openrc-run

name=“dnscrypt-proxy”

: ${dnscrypt_proxy_enable:=YES}
: ${dnscrypt_proxy_config=/usr/local/etc/dnscrypt-proxy.conf} # config file
: ${dnscrypt_proxy_uid=_dnscrypt-proxy} # User to run daemon as
: ${dnscrypt_proxy_resolver=d0wn-nl-ns2} # resolver to use
: ${dnscrypt_proxy_list=/usr/local/share/dnscrypt-proxy/dnscrypt-resolvers.csv} # ResolverList
: ${dnscrypt_proxy_pidfile=/var/run/dnscrypt-proxy.pid} # Path to pid file
: ${dnscrypt_proxy_logfile=/var/log/dnscrypt-proxy.log} # Path to log file

BINARY=/usr/local/sbin/dnscrypt-proxy
args="-d -p ${dnscrypt_proxy_pidfile} -l ${dnscrypt_proxy_logfile} -R ${dnscrypt_proxy_resolver} -L ${dnscrypt_proxy_list} ${dnscrypt-proxy_config}"

depend()
{
need localmount
before pcdm
}
start()
{
ebegin "Starting $name"
start-stop-daemon --start --exec $BINARY --$args
eend $?
}

But when I try to start the service I get this :

[beni@bsdaddict] ~% sudo service dnscrypt-proxy start
/usr/local/etc/init.d/dnscrypt-proxy: run_rc_command: not found

  • dnscrypt-proxy: error loading /usr/local/etc/init.d/dnscrypt-proxy
  • ERROR: dnscrypt-proxy failed to start
    [beni@bsdaddict] ~%

I thought that the run_rc_command was not needed in an openrc script (only in a bash script) ?
What am I doing wrong ?


#2

Ok, I see a couple problems with the OpenRC script you posted, so try this slightly modified/fixed version instead:

#!/sbin/openrc-run
name="dnscrypt-proxy"
command=/usr/local/sbin/dnscrypt-proxy

: ${dnscrypt_proxy_enable:=YES}
: ${dnscrypt_proxy_config=/usr/local/etc/dnscrypt-proxy.conf} # config file
: ${dnscrypt_proxy_uid=_dnscrypt-proxy} # User to run daemon as
: ${dnscrypt_proxy_resolver=d0wn-nl-ns2} # resolver to use
: ${dnscrypt_proxy_list=/usr/local/share/dnscrypt-proxy/dnscrypt-resolvers.csv} # ResolverList
: ${dnscrypt_proxy_pidfile=/var/run/dnscrypt-proxy.pid} # Path to pid file
: ${dnscrypt_proxy_logfile=/var/log/dnscrypt-proxy.log} # Path to log file

command_args="-d -p ${dnscrypt_proxy_pidfile} -l ${dnscrypt_proxy_logfile} -R ${dnscrypt_proxy_resolver} -L ${dnscrypt_proxy_list} ${dnscrypt-proxy_config}"

depend()
{
need localmount
before pcdm
}

Double check whether the “-d” flag is used to “daemonize” the process. If so, then make sure you remove that flag (OpenRC handles the backround-ing of the process - no need for the app to force it otherwise you end up with PID mismatches for the running process).

To Use (just for completeness - I think you probably already know this part):

  1. Replace/write this script into “/usr/local/etc/init.d/dnscrypt-proxy”
  2. Make sure the script is set as executable
  3. Use the “service” command to start/stop and “rc-update” to enable/disable

If this works for you, let me know and we can commit this service to the port for you.


#3

Your modifications seem to have done the trick :

[beni@bsdaddict] ~% sudo service dnscrypt-proxy start

  • Starting dnscrypt-proxy …
    Fri Jul 7 20:04:14 2017 [INFO] + DNS Security Extensions are supported
    Fri Jul 7 20:04:14 2017 [INFO] + Provider supposedly doesn’t keep logs

I don’t get my prompt back, but dnscrypt-proxy is running. Can this come from leaving out the “-d” (daemonize) option ?
From the man :
-d, --daemonize: detach from the current terminal and run the server in background.

Thanks for the help beanpole135 !


#4

Update : the “-d” (daemonize option) seems needed to start without problems :

It fails to start at boot. From dmesg :
[beni@bsdaddict] ~% sudo dmesg -a | grep dnscrypt-proxy
Password:
^[[1m^[[32m*^[[m Starting dnscrypt-proxy^[[K …
0x102c5c7 <+0xb38f> at /usr/local/sbin/dnscrypt-proxy
pid 72642 (dnscrypt-proxy), uid 0: exited on signal 10
^[[1m^[[31m*^[[m start-stop-daemon: failed to start /usr/local/sbin/dnscrypt-proxy'\^[[K Jul 8 14:51:45 /usr/local/etc/init.d/dnscrypt-proxy[72103]: start-stop-daemon: failed to start/usr/local/sbin/dnscrypt-proxy’
^[[1m^[[31m*^[[m Failed to start dnscrypt-proxy^[[K
^[[1m^[[31m*^[[m ERROR: dnscrypt-proxy failed to start^[[K
Jul 8 14:51:45 /usr/local/etc/init.d/dnscrypt-proxy[66785]: ERROR: dnscrypt-proxy failed to start
[beni@bsdaddict]

Adding the -d to command_args and restarting in konsole gives this :
[beni@bsdaddict] ~% sudo service dnscrypt-proxy start
Password:

  • Caching service dependencies … [ ok ]
  • Starting dnscrypt-proxy …
    Sat Jul 8 14:56:02 2017 [INFO] + DNS Security Extensions are supported
    Sat Jul 8 14:56:02 2017 [INFO] + Provider supposedly doesn’t keep logs [ ok ]
    [beni@bsdaddict]

And it seems up and running :
[beni@bsdaddict] ~% ps -aux | grep dnscrypt-proxy
root 69686 0.0 0.0 26088 3280 - INs 14:55 0:00.03 /usr/local/sbin/dnscrypt-proxy -p /var/run/dnscrypt-proxy.pid -l /var/log/dnscrypt-proxy.log -R d0wn-nl-ns2 -L /usr/local/share/dnscrypt-proxy/dnscrypt-resolvers.csv proxy_config
beni 47199 0.0 0.0 14960 2336 0 SN+ 14:56 0:00.00 grep dnscrypt-proxy
[beni@bsdaddict] ~%