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