aboutsummaryrefslogtreecommitdiff
path: root/network/AdGuardHome/rc.AdGuardHome
blob: 3c52405ce986c0528fdd601e40e1bbcf44472202 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# Start/stop/restart the AdGuard Home

name="AdGuardHome"
user="dnsproxy"
workdir=/var/lib/"$name"
configdir=/etc/"$name"
pidfiles=/run/"$name"
mkdir -p $pidfiles $workdir $configdir
chmod 0700 $pidfiles $workdir
if /bin/id "$user" &>/dev/null; then
  chown $user:$user $pidfiles
  chown -R $user:$user $workdir
  chown -R $user:$user $configdir
  daemon="/usr/bin/daemon --name=$name --pidfiles=$pidfiles --user=$user"
else
  daemon="/usr/bin/daemon --name=$name --pidfiles=$pidfiles"
fi

start_AdGuardHome() {
if $daemon --running; then
  echo "$name is already running"
elif [ ! -f /etc/AdGuardHome/AdGuardHome.yaml ];then
  /usr/sbin/AdGuardHome --config /etc/AdGuardHome/AdGuardHome.yaml \
    --work-dir $workdir
else
  echo "Starting $name..."
  $daemon -- /usr/sbin/AdGuardHome --config /etc/AdGuardHome/AdGuardHome.yaml \
    --work-dir $workdir --no-check-update
fi
}

stop_AdGuardHome() {
if $daemon --running; then
  echo "Stopping $name..."
  $daemon --stop
else
  echo "$name is not running"
fi
}

restart_AdGuardHome() {
  stop_AdGuardHome
  sleep 1
  start_AdGuardHome
}

status_AdGuardHome() {
  $daemon --running --verbose
}

case "$1" in
'start')
  start_AdGuardHome
  ;;
'stop')
  stop_AdGuardHome
  ;;
'restart')
  restart_AdGuardHome
  ;;
'status')
  status_AdGuardHome
  ;;
*)
  echo "usage $0 start|stop|restart|status"
esac