aboutsummaryrefslogtreecommitdiff
path: root/system/thinkfan/rc.thinkfan
blob: fae364cbe51a3375c8c0dcf1a5a084a78c5cd907 (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

NAME=thinkfan
BIN=/usr/bin/$NAME
CONFIG=/etc/thinkfan.conf
ARGS="-q -c $CONFIG"
PIDFILE=/var/run/$NAME.pid

thinkfan_start() {
  echo -n "Starting $NAME ... "
  if [ -e "$PIDFILE" ]; then
    echo "already running!"
  else
    $BIN $ARGS
    if [ $? -ne 0 ] ; then
      echo "failed to start!"
      return 1
    else
      echo "done!"
    fi
  fi
}

thinkfan_status() {
    if [ $(pgrep -f $BIN) ]; then
			echo "thinkfan is running"

			if [ ! -e $PIDFILE ]; then
				echo "Warning: Missing pid file $PIDFILE"
			fi

			exit 0
		else
			echo "thinkfan is stopped"

			if [ -e $PIDFILE ]; then
				echo "Detected stale pid file $PIDFILE"
			fi

			exit 0
		fi
}

thinkfan_stop() {
  echo -n "Stopping $NAME ... "
  if [ -e "$PIDFILE" ]; then
    kill -TERM $(cat $PIDFILE) > /dev/null 2>&1
    echo "done!"
    rm -f "$PIDFILE"
  else
    echo "not running!"
  fi
}

thinkfan_restart() {
  thinkfan_stop
  sleep 1
  thinkfan_start
}

case "$1" in
'start')
  thinkfan_start
  ;;
'status')
  thinkfan_status
  ;;
'stop')
  thinkfan_stop
  ;;
'restart')
  thinkfan_restart
  ;;
*)
  echo "usage $0 start|stop|restart|status"
esac