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