aboutsummaryrefslogtreecommitdiff
path: root/system/OpenSnitch/rc.opensnitchd
blob: 7e8c30fa1c24182b8688ab73dd48ef45a1226311 (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
#!/bin/sh

# Start opensnitchd:
start_opensnitchd() {
  echo "Start Opensnitch"

  if [ -x /usr/bin/opensnitchd ]; then
    [ ! -d /etc/opensnitchd/rules ] && mkdir -p /etc/opensnitchd/rules
    chown -R root:root /etc/opensnitchd
    chown root:root /var/log/opensnitchd.log
    chmod -R 755 /etc/opensnitchd
    chmod -R 644 /etc/opensnitchd/rules
    chmod 600 /var/log/opensnitchd.log
  fi

  /usr/bin/opensnitchd -rules-path /etc/opensnitchd/rules -log-file /var/log/opensnitchd.log > /dev/null 2>&1 &
}

# Stop opensnitchd:
stop_opensnitchd() {
  if /usr/bin/pgrep -f /usr/bin/opensnitchd >/dev/null; then
    echo "Stopping application firewall"
    /usr/bin/pkill -SIGINT opensnitchd
  else
    echo "Opensnitch is not running"
    exit 1
  fi
}

# Restart opensnitchd:
restart_opensnitchd() {
  stop_opensnitchd
  sleep 1
  start_opensnitchd
}

case "$1" in
'start')
  start_opensnitchd
  ;;
'stop')
  stop_opensnitchd
  ;;
'restart')
  restart_opensnitchd
  ;;
*)
  echo "usage $0 start|stop|restart"
esac