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