summaryrefslogtreecommitdiff
path: root/openwrt/rhctl/files/heartbeatclient.init
blob: 002dfb30b71e845c04f824d2083e3d8efdf72880 (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
69
70
71
72
73
74
75
76
#!/bin/sh /etc/rc.common
START=72

BIN=heartbeatclient
DAEMON=/usr/bin/$BIN
DESC=$BIN
RUN_D=/var/run/rhctl
PIDFILE=$RUN_D/$BIN.pid


option_cb() {
  local varname="$1"
  local value="$2"

  if ! echo "$CONFIG_OPTIONS" | grep " $varname " > /dev/null; then
    CONFIG_OPTIONS="$CONFIG_OPTIONS $varname "
  fi
}

start_daemon() {
  local option
  local value
  local args=""

  local status="OK"
  for option in $CONFIG_OPTIONS
  do
    config_get value "$1" "$option"
    option=`echo $option | tr '_' '-'`
    if [ $option = "led" ]; then
      local led_path
      eval "led_path=\${LED_${value}}"
      if [ -z "$led_path" ]; then
        status="OK but led not found"
      else
        led_path="/sys/class/leds/$led_path/brightness"
        args="$args --led $led_path"
      fi
    elif [ -n "$value" ]; then
      args="$args --$option $value"
    fi
  done
  $DAEMON --write-pid $PIDFILE $args || status="failed"
  echo -n " ($status)"
}

get_led()
{
  local name
  local sysfs
  config_get name $1 name
  config_get sysfs $1 sysfs
  eval LED_$name=$sysfs
}

start() {
  echo -n "Starting $DESC:"
  config_load "system"
  config_foreach get_led "led"
  config_load "rhctl"
  mkdir -p $RUN_D
  config_foreach start_daemon "heartbeatclient"
  echo "."
}

stop() {
  echo -n "Stopping $DESC:"
  if [ -f $PIDFILE ]; then
    kill `cat $PIDFILE` > /dev/null 2>&1
    rm -f $PIDFILE > /dev/null 2>&1
    echo -n " (Ok)"
  else
    echo -n " (not running)"
  fi
  echo "."
}