aboutsummaryrefslogtreecommitdiff
path: root/dns/dnscrypt-proxy/files/dnscrypt-proxy_multi.in
blob: db3ccf21bf8ee3b23ee39770bffd0fa1929d3c51 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: dnscrypt_proxy
# REQUIRE: SERVERS cleanvar ldconfig
# BEFORE: named local_unbound unbound
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable dnscrypt-proxy:
#
# dnscrypt_proxy_instances (str): Set to "dnscrypt_proxy" by default.
#                                 List of dnscrypt_proxy instance id's,
#                                 e.g. "dnscrypt_proxy_1 dnscrypt_proxy_2", etc.
# {instance_id}_enable (bool):    Set to NO by default.
#                                 Set to YES to enable dnscrypt-proxy.
# {instance_id}_uid (str):        Set to "_dnscrypt-proxy" by default.
#                              	  User to switch to after starting.
# {instance_id}_resolver (str):   Set to "random" by default.
#                              	  Better to select one of your own choice.
# {instance_id}_pidfile (str):    default: "/var/run/dnscrypt-proxy.pid"
#                              	  Location of pid file.
# {instance_id}_logfile (str):	  default: "/var/log/dnscrypt-proxy.log"
#                                 Location of log file.
#
# To redirect a local resolver through dnscrypt-proxy, point it at 127.0.0.2
# and add the following to rc.conf:
# ifconfig_lo0_alias0="inet 127.0.0.2 netmask 0xffffffff"
# dnscrypt_proxy_flags='-a 127.0.0.2'

. /etc/rc.subr

name=dnscrypt_proxy
rcvar=dnscrypt_proxy_enable

load_rc_config ${name}

: ${dnscrypt_proxy_instances="${name}"}
: ${dnscrypt_proxy_enable:=NO}

dnscrypt_proxy_enable_tmp=${dnscrypt_proxy_enable}

command=%%PREFIX%%/sbin/dnscrypt-proxy
procname=%%PREFIX%%/sbin/dnscrypt-proxy

for i in $dnscrypt_proxy_instances; do
    name=${i}

    eval ${name}_enable=${dnscrypt_proxy_enable_tmp}
    rcvar=${name}_enable

    load_rc_config ${i}

    eval dnscrypt_proxy_uid_tmp=\${${i}_uid}
    eval dnscrypt_proxy_resolver_tmp=\${${i}_resolver}
    eval dnscrypt_proxy_pidfile_tmp=\${${i}_pidfile}
    eval dnscrypt_proxy_logfile_tmp=\${${i}_logfile}

:   ${dnscrypt_proxy_uid_tmp:=_dnscrypt-proxy}       # User to run daemon as
:   ${dnscrypt_proxy_resolver_tmp:=random}            # resolver to use
:   ${dnscrypt_proxy_pidfile_tmp:=/var/run/${i}.pid} # Path to pid file
:   ${dnscrypt_proxy_logfile_tmp:=/var/log/${i}.log} # Path to log file

    command_args="-d -p ${dnscrypt_proxy_pidfile_tmp} -l ${dnscrypt_proxy_logfile_tmp} -u ${dnscrypt_proxy_uid_tmp} -R ${dnscrypt_proxy_resolver_tmp}"

    pidfile=${dnscrypt_proxy_pidfile_tmp}

    _rc_restart_done=false # workaround for: service dnscrypt-proxy restart

    run_rc_command "$1"
done