Mercurial > bottledash
comparison contrib/dashboardctl @ 33:70d50b6312e2
Initial commit of dashboardctl
author | Gernot Schulz <gernot@intevation.de> |
---|---|
date | Fri, 16 Oct 2015 16:16:33 +0200 |
parents | |
children | 7162616389a5 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 33:70d50b6312e2 |
---|---|
1 #!/usr/bin/env sh | |
2 | |
3 export DISPLAY=":0.0" | |
4 | |
5 OLDDB=/home/pi/incoming_dbs/tech_intern.db | |
6 NEWDB=/home/pi/incoming_dbs/tech_intern.db.new | |
7 | |
8 usage () { | |
9 cat << EOF | |
10 Usage: $0 [COMMAND] | |
11 | |
12 Commands: | |
13 --restart-bd Restart Bottledash | |
14 --reload-browser Reload dashboard/browser | |
15 --reload Restart Bottledash and reload the dashboard/browser | |
16 --check-db Check if a new DB is available | |
17 --smart-reload If a new DB is available, restart Bottledash and reload | |
18 the dashboard/browser | |
19 -h, --help This help | |
20 EOF | |
21 } | |
22 | |
23 start_bottledash () { | |
24 # taken from start-bottledash-hohup | |
25 nohup python3 /home/pi/bottledash/dash.py 2>&1 > $HOME/bottledash.log & | |
26 echo $! > $HOME/pid_bottledash | |
27 } | |
28 | |
29 stop_bottledash () { | |
30 kill $(cat $HOME/pid_bottledash) | |
31 } | |
32 | |
33 start_chromium () { | |
34 # taken from show-dashboard | |
35 rm -R $HOME/.cache/chromium/Default/Cache/ | |
36 DISPLAY=:0.0 nohup chromium --new --noerrdialogs --kiosk \ | |
37 http://localhost:8080 2>&1 > $HOME/show-dashboard.log & | |
38 echo $! > $HOME/pid_chromium | |
39 } | |
40 | |
41 | |
42 stop_chromium () { | |
43 kill $(cat pid_chromium) | |
44 } | |
45 | |
46 xdo_reload_chromium () { | |
47 # Start Chromium if necessary | |
48 if [ -f "$HOME/pid_bottledash" ] && [ -d /proc/$(cat "$HOME/pid_chromium") ]; then | |
49 # Send F5 to Chromium | |
50 WID=$(xdotool search --onlyvisible --class chromium | head -1) | |
51 xdotool windowactivate ${WID} | |
52 xdotool key F5 | |
53 else | |
54 start_chromium | |
55 fi | |
56 } | |
57 | |
58 check_new_db () { | |
59 if [ ! -f "$NEWDB" ]; then | |
60 echo 0 ; return | |
61 fi | |
62 OLDSIZE=$(md5sum $OLDDB | awk '{print $1}') | |
63 NEWSIZE=$(md5sum $NEWDB | awk '{print $1}') | |
64 if [ "$OLDSIZE" != "$NEWSIZE" ]; then | |
65 echo 1 | |
66 else | |
67 echo 0 | |
68 fi | |
69 } | |
70 | |
71 update_db () { | |
72 if [ $(check_new_db) -eq 1 ]; then | |
73 mv "$NEWDB" "$OLDDB" | |
74 fi | |
75 } | |
76 | |
77 case $1 in | |
78 '--restart-bd') | |
79 stop_bottledash | |
80 start_bottledash | |
81 ;; | |
82 '--reload-browser') | |
83 xdo_reload_chromium | |
84 ;; | |
85 '--reload') | |
86 stop_bottledash | |
87 start_bottledash | |
88 sleep 10 | |
89 xdo_reload_chromium | |
90 ;; | |
91 '--check-db') | |
92 check_new_db | |
93 ;; | |
94 '--smart-reload') | |
95 if [ $(check_new_db) -eq 1 ]; then | |
96 update_db | |
97 stop_bottledash | |
98 start_bottledash | |
99 sleep 10 | |
100 xdo_reload_chromium | |
101 fi | |
102 ;; | |
103 '-h'|'--help') | |
104 usage | |
105 exit 0 | |
106 ;; | |
107 *) | |
108 echo "ERROR: unknown command: $1" >&2 | |
109 usage | |
110 exit 2 | |
111 ;; | |
112 esac | |
113 | |
114 # vim: set ft=sh : |