summaryrefslogtreecommitdiff
path: root/network/znc/rc.znc
blob: 85d58929ceb8107b7167d8e4626887cc577a9116 (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
#!/bin/sh

# Start/stop/restart znc

# User account under which ZNC should run; only change this if you 
# know what you are doing :-)
ZNC_USER="_ZNC_USER_"

# First, a sanity check
if [[ ! -e /etc/znc/configs/znc.conf ]]; then
   echo "Warning: /etc/znc/configs/znc.conf does not exist."
   echo "You should create a config file by running the following command:"
   echo "  su - $ZNC_USER -c '/usr/bin/znc --makeconf --datadir=/etc/znc'"
   exit 1
fi

znc_start() {
   if [[ -e /var/lock/znc ]]; then
      echo "ZNC is already running, or there is a stale lock file at "
      echo "/var/lock/znc - if you are sure that znc is not already "
      echo "running, then remove the lock and try again."
      return 1
   else
      su - $ZNC_USER -c '/usr/bin/znc --datadir /etc/znc' && touch /var/lock/znc
      return 0
   fi
}

znc_stop() {
   killall znc 2>/dev/null
   RETVAL=$?
   if (( "$RETVAL" != 0 )); then
      echo "ZNC does not appear to be running..."
   else
      rm -f /var/lock/znc
   fi
   return $RETVAL
}  

znc_restart() {
   znc_stop
   sleep 1
   znc_start
}

case "$1" in
   'start')
   znc_start
   ;;
   'stop')
   znc_stop
   ;;
   'restart')
   znc_restart
   ;;
   *)
   echo "Usage: $0 start|stop|restart"
   exit 1
esac

exit $?