summaryrefslogtreecommitdiff
path: root/source/n/netatalk/rc.atalk.new
blob: bc079b5805bed5d3c670943891389fa77922dc6f (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
#!/bin/sh
# Start/stop/restart the netatalk daemon.

netatalk_start() {
  if [ -x /usr/sbin/netatalk ]; then

    LINES="$(grep "^[^;]" /etc/netatalk/afp.conf | wc -l)"
    if [ "$LINES" -lt "2" ]; then
      echo "netatalk is not configured.... exiting."
      exit
    fi 

    echo "Starting netatalk:  /usr/sbin/netatalk"
    /usr/sbin/netatalk
  fi
}

# Stop netatalk
netatalk_stop() {
  echo "Stopping netatalk."
  /usr/bin/pkill --ns $$ -f "^/usr/sbin/netatalk" 2> /dev/null
}

# Restart netatalk
netatalk_restart() {
  netatalk_stop
  sleep 1
  netatalk_start
}

# Check if netatalk is running
netatalk_status() {
  PID="$(/usr/bin/pgrep --ns $$ -f "^/usr/sbin/netatalk" 2> dev/null)
  if [ $PID ]; then
    echo "netatalk is running.  PID: $PID"
  else
    echo "netatalk is stopped."
    exit 1
  fi
}

case "$1" in
'start')
  netatalk_start
  ;;
'stop')
  netatalk_stop
  ;;
'restart')
  netatalk_restart
  ;;
'status')
  netatalk_status
  ;;
*)
  echo "usage $0 start|stop|restart|status"
esac