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