X-Git-Url: https://git.rvb.name/weathermon.git/blobdiff_plain/7edb3771717d15f7c36d8459fa12b3d6f76d7d9a..e32107a7fe79ce34f3bdf860410a6d5455efdca7:/init.d/weathermon?ds=inline diff --git a/init.d/weathermon b/init.d/weathermon new file mode 100755 index 0000000..cb1822a --- /dev/null +++ b/init.d/weathermon @@ -0,0 +1,47 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2007-2014 OpenWrt.org + +START=93 +STOP=45 + +USE_PROCD=1 + +PROG=/usr/bin/weathermon +NICEPRIO=-1 + +BACKUP_DIR=`uci get weathermon.process.backup_dir` +BACKLOGDB=`uci get weathermon.process.backlogdb` +LOGDB=`uci get weathermon.process.logdb` +WORK_DIR=`uci get weathermon.process.working_dir` + +start_service() { + + mkdir -p "$WORK_DIR" + + if [ ! -z "$BACKLOGDB" ] && [ ! -f "$BACKLOGDB" ]; then + BACKLOG_BASE=$(basename "$BACKLOGDB") + cp "$BACKUP_DIR/$BACKLOG_BASE" "$BACKLOGDB" + fi + + if [ ! -z "$LOGDB" ] && [ ! -f "$LOGDB" ]; then + LOG_BASE=$(basename "$LOGDB") + cp "$BACKUP_DIR/$LOG_BASE" "$LOGDB" + fi + + procd_open_instance + procd_set_param command "$PROG" + procd_set_param nice "$NICEPRIO" + procd_set_param respawn ${respawn_threshold:-600} ${respawn_timeout:-5} ${respawn_retry:-5} + procd_close_instance +} + +stop_service() { + killall weathermon + killall weathermon-iio + if [ ! -z "$BACKLOGDB" ] && [ -f "$BACKLOGDB" ]; then + cp "$BACKLOGDB" "$BACKUP_DIR"/ + fi + if [ ! -z "$LOGDB" ] && [ -f "$BACKLOGDB" ]; then + cp "$LOGDB" "$BACKUP_DIR"/ + fi +}