Fixing /etc/init.d/dnscrypt-proxy

Hi,

I am using dnscrypt-proxy from https://github.com/jedisct1/dnscrypt-proxy as there is a release for arm, on my router.

The problem is that the dnscrypt-proxy in /etc/init.d is written for some kind of Linux, and not OpenWRT/LEDE.

Can someone let me know what the following commands means, and how to fix these?
[ -e /etc/sysconfig/$name ] && . /etc/sysconfig/$name

is_running() {
[ -f "$pid_file" ] && ps $(get_pid) > /dev/null 2>&1
}

On OpenWRT/LEDE, ps does not support a parameter.

The entire script is here and I've fixed parts of it, but the above, I do not know how to fix.
https://gist.github.com/chuacw/27afa4cd6dee2c4a849268f1f2f32396

I'ved updated my dnscrypt-proxy to the following, which works:

#!/bin/sh /etc/rc.common
# by chuacw 18 Apr 2018

cmd="/usr/sbin/dnscrypt-proxy"
name=$(basename $(readlink -f $cmd))
stdout_log="/var/log/$name.log"
pid_file="/var/run/$name.pid"
stderr_log="/var/log/$name.err"
arguments="-config /etc/config/dnscrypt-proxy.toml -logfile $stdout_log"
start_cmd="start-stop-daemon -b -S -m -p $pid_file -x $name -- $arguments"
stop_cmd="start-stop-daemon -K -p $pid_file"

# echo start cmd is: $start_cmd
# echo stop cmd is: $stop_cmd

get_pid() {
  cat "$pid_file"
}

start() {
  echo "Starting DNSCrypt proxy..."
  $start_cmd
  echo "See ps result for confirmation"
  ps | grep "$name"
}

stop() {
  echo "Stopping DNSCrypt proxy..."
  $stop_cmd
  echo "See ps result below for confirmation"
  ps | grep "$name"
  rm $pid_file
}

Take a look here:

You can add this repo to your feeds.conf if you building your own firmware.

Otherwise you can use the init script from his repo.
The init script has procd support and works quite well.

Here is my simple script:

#!/bin/sh /etc/rc.common
START=99

DNSCRYPTPROXY=/usr/sbin/dnscrypt-proxy
CONFIG=/etc/dnscrypt-proxy2/dnscrypt-proxy.toml
PIDFILE=/var/run/dnscrypt-proxy2.pid

start() {

	if [ -f "$PIDFILE" ] && kill -0 $(cat "$PIDFILE"); then
	
		echo 'dnscrypt-proxy2 already running...' >&2
		
		return 1
	fi	
		echo 'Starting dnscrypt-proxy2...' >&2
		
		$DNSCRYPTPROXY -config $CONFIG -pidfile $PIDFILE -syslog &
}

stop() {

	if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then
	
		echo 'dnscrypt-proxy2 not running...' >&2
		
		return 1
	fi
	
	echo 'Stopping dnscrypt-proxy2...' >&2
		
	kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE"
		
	echo 'dnscrypt-proxy2 stopped...' >&2
}

Not as good as inkblots but it works x)

1 Like