summaryrefslogtreecommitdiffstats
path: root/system/sleepd/rc.sleepd
blob: 66587a2f8c7c8b849798d742ff5d2462ec3ac8a8 (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
77
78
79
#!/bin/sh

# /etc/rc.d/rc.sleepd
# Start/stop/restart the sleepd daemon

PIDFILE="/var/run/sleepd.pid"
DAEMON="/usr/sbin/sleepd"

. /etc/sleepd.conf

# Define start and stop functions

sleepd_start() {
  [ $UID -eq 0 ] || exit 4
  if [ -e $PIDFILE ]; then
    echo "sleepd appears to already be running. If this is not the case,"
    echo "remove $PIDFILE and try again."
    exit 1
  else
    echo "Starting sleepd: $DAEMON"
    sleepd $PARAMS > /dev/null 2>&1
    ps -p `cat $PIDFILE` > /dev/null 2>&1
    if [ "$?" == 1 ]; then
      rm -f $PIDFILE
      echo "ERROR: $DAEMON failed to start."
      echo "ERROR: For more verbosity, run \"$DAEMON -n -v\" manually."
      echo "ERROR: Exiting..."
    fi
  fi
}

sleepd_force_stop() {
  [ $UID -eq 0 ] || exit 4
  echo "Force stopping sleepd..."
  if [ -e $PIDFILE ]; then
    kill $(cat $PIDFILE) 2>/dev/null
    rm -f $PIDFILE 2>/dev/null
  else
    killall -9 sleepd 2>/dev/null
  fi
}

sleepd_stop() {
  [ $UID -eq 0 ] || exit 4
  echo "Stopping sleepd..."
  if [ -e $PIDFILE ]; then
    kill $(cat $PIDFILE) 2>/dev/null
    rm -f $PIDFILE 2>/dev/null
  fi
}

sleepd_status() {
  sleepctl status
}

# See how we were called and take appropriate action

case $1 in
  start)
    sleepd_start
   ;;
  stop)
    sleepd_stop
   ;;
  force_stop)
    sleepd_force_stop
   ;;
  restart)
    sleepd_force_stop
    sleepd_start
   ;;
  status)
    sleepd_status
   ;;
  *)
    echo "Usage: $0 {start|stop|force_stop|restart|status}"
    exit 1
   ;;
esac