diff options
author | pks <pks@pks.rocks> | 2021-05-16 18:23:12 +0200 |
---|---|---|
committer | pks <pks@pks.rocks> | 2021-05-16 18:23:12 +0200 |
commit | 8a89176b2b563ad20c21eea6f31cef01c46582dc (patch) | |
tree | 7e9f0a44e9d52d6ed2e957ca4b524b2fa3b61f6c /config | |
parent | 899ba88b76a2f01b1bab87fbb960c2277435c521 (diff) |
restart
Diffstat (limited to 'config')
-rwxr-xr-x | config/init.d/power-logger | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/config/init.d/power-logger b/config/init.d/power-logger index f1ac7a7..e50d080 100755 --- a/config/init.d/power-logger +++ b/config/init.d/power-logger @@ -8,32 +8,24 @@ # Short-Description: power-logger ### END INIT INFO -export SUFFIX=$(date +'%Y-%m-%d-%H:%M:%S') +export SUFFIX=$(date +'%Y-%m-%dT%H:%M:%S') export USER=pks export GROUP=pks -export DIR=/home/$USER/mqtt_client/ +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" - rm -f $DIR/stop - if [ ! -f $DIR/power.db ]; then - runuser -l $USER -c "$DIR/db-create.sh $DIR/power.db" - fi - mkdir -p $DIR/log - chown -R $USER:$GROUP $DIR/log - runuser -l $USER -c "source $DIR/env/bin/activate && python $DIR/mqtt-receiver.py 2> >(cat > $DIR/log/power.$SUFFIX.err) | tee >(cat > $DIR/log/power.$SUFFIX.out) | $DIR/db-from-log.sh $DIR/power.db 2> >(cat > $DIR/log/power.db-from-log.$SUFFIX.err)" & - echo $! > /run/power-logger.pid2 + 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" - runuser -l $USER -c "touch $DIR/stop" - sleep 3 - if [ -f /run/power-logger.pid2 ]; then - kill $(cat /run/power-logger.pid2) &>/dev/null - rm -f /run/power-logger.pid2 - fi - rm -f $DIR/stop + kill $(cat /run/power-logger.pid) + rm -f /run/power-logger.pid ;; *) echo "Usage: /etc/init.d/power-logger {start|stop}" |