aboutsummaryrefslogtreecommitdiff
path: root/system/i8kutils/rc.i8kmon
blob: 1d88d42ccbb57efdbb273736b52ab6cb9d88e4c2 (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
68
#!/bin/sh
# Start/stop/restart i8kmon.

I8KMON_PARAMS="--auto --daemon"

# Start i8kmon
i8kmon_start() {
  if [ -x /usr/bin/i8kmon -a -f /proc/i8k ]; then
    echo "Starting i8kmon daemon: /usr/bin/i8kmon $I8KMON_PARAMS &"
    /usr/bin/i8kmon $I8KMON_PARAMS &
  fi
}

# Stop i8kmon
i8kmon_stop() {
  echo "Stopping i8kmon daemon"
  pkill -f "tclsh /usr/bin/i8kmon -- $I8KMON_PARAMS"
}

# Check status
i8kmon_status() {
  pgrep -f "tclsh /usr/bin/i8kmon -- $I8KMON_PARAMS" > /dev/null
  local I8KMON_STATUS=$?
  if [ $I8KMON_STATUS -ne 0 ]; then
    return 1
  fi
}

# Restart i8kmon
i8kmon_restart() {
  $0 stop
  sleep 1
  $0 start
}

case "$1" in
'start')
  if ( ! i8kmon_status ); then
    i8kmon_start
  else
    echo "i8kmon is already running"
  fi
  ;;

'stop')
  if ( i8kmon_status ); then
    i8kmon_stop
  else
    echo "i8kmon is already stopped"
  fi
  ;;

'status')
  if ( i8kmon_status ); then
    echo "i8kmon is currently running"
  else
    echo "i8kmon is NOT running"
  fi
  ;;

'restart')
  i8kmon_restart
  ;;

*)
  echo "Usage: $0 start|stop|status|restart"
  ;;
esac