summaryrefslogtreecommitdiffstats
path: root/network/AdGuardHome/rc.AdGuardHome
blob: f872e51e09241f654c33d8a41a4c04ed7b301288 (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
#!/bin/sh
# Start/stop/restart the AdGuard Home

bin=/usr/sbin/AdGuardHome
config=/etc/AdGuardHome.yaml
workdir=/var/lib/AdGuardHome
pidfile=/run/AdGuardHome.pid

start_AdGuardHome() {
  echo "Starting AdGuard Home... "
  if [ -f $pidfile ]; then
      echo "AdGuard Home is already running with PID $(cat ${pidfile})."
      exit 0
  fi
  mkdir -p $workdir
  nohup $bin --config $config --work-dir $workdir --no-check-update \
      --pidfile $pidfile 0<&- &>/dev/null &
}

stop_AdGuardHome() {
  echo "Stoppping AdGuard Home... "
  [ -f $pidfile ] && kill $(cat ${pidfile})
}

restart_AdGuardHome() {
  stop_AdGuardHome
  sleep 1
  start_AdGuardHome
}

status_AdGuardHome() {
  if [ -f $pidfile ]; then
    echo "AdGuard Home is running with PID $(cat ${pidfile})."
  else
    echo "AdGuard Home is stopped."
    exit 1
  fi
}

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