Все-таки переподключение к брокеру лучше выполнять вручную...
[weathermon.git] / init.d / weathermon
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2007-2014 OpenWrt.org
3
4 START=93
5 STOP=45
6
7 USE_PROCD=1
8
9 PROG=/usr/bin/weathermon
10 NICEPRIO=-1
11
12 BACKUP_DIR=`uci get weathermon.process.backup_dir`
13 BACKLOGDB=`uci get weathermon.process.backlogdb` 
14 LOGDB=`uci get weathermon.process.logdb` 
15 WORK_DIR=`uci get weathermon.process.working_dir`
16
17 start_service() {
18
19         mkdir -p "$WORK_DIR"
20
21         if [ ! -z "$BACKLOGDB" ]; then
22
23                 sqlite3 $BACKLOGDB "select * from queue limit 1" > /dev/null
24         
25                 if [ "$?" != "0" ]; then
26                         BACKLOG_BASE=$(basename "$BACKLOGDB")
27                         cp "$BACKUP_DIR/$BACKLOG_BASE" "$BACKLOGDB"
28                 fi
29                         
30         fi
31
32         if [ ! -z "$LOGDB" ]; then
33         
34                 sqlite3 $LOGDB "select * from log limit 1" > /dev/null
35         
36                 if [ "$?" != "0" ]; then
37                         LOG_BASE=$(basename "$LOGDB")
38                         cp "$BACKUP_DIR/$LOG_BASE" "$LOGDB"
39                 fi
40
41         fi
42
43         procd_open_instance
44         procd_set_param command "$PROG"
45         procd_set_param nice "$NICEPRIO"
46         procd_set_param respawn
47         procd_close_instance
48 }
49
50 stop_service() {
51         killall weathermon
52         killall weathermon-iio
53         /usr/bin/weather-backup
54 }