aboutsummaryrefslogtreecommitdiffstats
path: root/templates/usr_local_etc_rc.d_do_dyndns.j2
blob: 6c4c18e6991797731adac27764bfb63f45535c3e (plain)
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
#!/bin/sh
#
# PROVIDE: do_dyndns
# REQUIRE: NETWORKING
# KEYWORD: shutdown

. /etc/rc.subr

name="do_dyndns"
rcvar=do_dyndns_enable

extra_commands="status"
rcvars="do_dyndns_enable do_dyndns_domain do_dyndns_hostname do_dyndns_if4 do_dyndns_interval do_dyndns_auth_file"
stop_cmd="do_dyndns_stop"

load_rc_config $name

: "${do_dyndns_enable:=NO}"
: "${do_dyndns_interval:=1m}"
: "${do_dyndns_hostname:=@}"
: "${do_dyndns_auth_file:=/usr/local/etc/do_dyndns_auth}"

pidfile="/var/run/${name}.pid"
logfile="/var/log/${name}"

command="/usr/sbin/daemon"
command_args="-cfr -P ${pidfile} -o ${logfile} /bin/sh -c '
  export PATH=\"/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin\"
  export DO_DYNDNS_DOMAIN=\"${do_dyndns_domain}\"
  export DO_DYNDNS_HOSTNAME=\"${do_dyndns_hostname}\"
  export DO_DYNDNS_IF4=\"${do_dyndns_if4}\"
  export DO_DYNDNS_INTERVAL=\"${do_dyndns_interval}\"
  export DO_DYNDNS_AUTH_FILE=\"${do_dyndns_auth_file}\"

  exec /usr/local/bin/do_dyndns.sh
'"

do_dyndns_stop() {
    echo "Stopping ${name} with SIGINT..."
    if [ -f "${pidfile}" ]; then
        kill -INT "$(cat "${pidfile}")"
        sleep 5
        if kill -0 "$(cat "${pidfile}")" 2>/dev/null; then
            echo "Process didn't exit, sending SIGKILL..."
            kill -KILL "$(cat "${pidfile}")"
        fi
        rm -f "${pidfile}"
    else
        echo "${name}: no pidfile found"
    fi
}

run_rc_command "$1"