summaryrefslogtreecommitdiff
path: root/config/init.d/power-logger
blob: e50d080f1950227094dd80b5a03e3881950f4f1b (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
#!/bin/sh
### BEGIN INIT INFO
# Provides:          power-logger
# Required-Start:    $all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: power-logger
### END INIT INFO

export SUFFIX=$(date +'%Y-%m-%dT%H:%M:%S')
export USER=pks
export GROUP=pks
export DIR=/usr/local/src/power_logger
export GEM_HOME=/home/$USER/.local/lib/ruby
export GEM_PATH=/home/$USER/.local/lib/ruby

case "$1" in
  start)
    echo "Starting power-logger"
    su - $USER -c "mkdir -p $DIR/log $DIR/db"
    su - $USER -c "$DIR/power-logger.rb -d $DIR/db/power.db -l $DIR/log/power.$SUFFIX.gz" &
    echo $! > /run/power-logger.pid
    ;;
  stop)
    echo "Stopping power-logger"
    kill $(cat /run/power-logger.pid)
    rm -f /run/power-logger.pid
    ;;
  *)
    echo "Usage: /etc/init.d/power-logger {start|stop}"
    exit 1
    ;;
esac

exit 0