Mercurial > bottledash
annotate contrib/dashboardctl @ 34:7162616389a5
Change PID and log file names
author | Gernot Schulz <gernot@intevation.de> |
---|---|
date | Mon, 19 Oct 2015 13:36:37 +0200 |
parents | 70d50b6312e2 |
children | 295e3253bb49 |
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 |
33
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
32 } |
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 stop_bottledash () { |
34
7162616389a5
Change PID and log file names
Gernot Schulz <gernot@intevation.de>
parents:
33
diff
changeset
|
35 kill $(cat $BOTTLEDASH_PID) |
33
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 |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
38 start_chromium () { |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
39 # taken from show-dashboard |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
40 rm -R $HOME/.cache/chromium/Default/Cache/ |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
41 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
|
42 http://localhost:8080 2>&1 > $CHROMIUM_LOG & |
7162616389a5
Change PID and log file names
Gernot Schulz <gernot@intevation.de>
parents:
33
diff
changeset
|
43 echo $! > $CHROMIUM_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 |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
47 stop_chromium () { |
34
7162616389a5
Change PID and log file names
Gernot Schulz <gernot@intevation.de>
parents:
33
diff
changeset
|
48 kill $(cat $CHROMIUM_PID) |
33
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 |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
51 xdo_reload_chromium () { |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
52 # Start Chromium if necessary |
34
7162616389a5
Change PID and log file names
Gernot Schulz <gernot@intevation.de>
parents:
33
diff
changeset
|
53 if [ -f "$BOTTLEDASH_PID" ] && [ -d /proc/$(cat "$CHROMIUM_PID") ]; then |
33
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
54 # Send F5 to Chromium |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
55 WID=$(xdotool search --onlyvisible --class chromium | head -1) |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
56 xdotool windowactivate ${WID} |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
57 xdotool key F5 |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
58 else |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
59 start_chromium |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
60 fi |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
61 } |
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 check_new_db () { |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
64 if [ ! -f "$NEWDB" ]; then |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
65 echo 0 ; return |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
66 fi |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
67 OLDSIZE=$(md5sum $OLDDB | awk '{print $1}') |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
68 NEWSIZE=$(md5sum $NEWDB | awk '{print $1}') |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
69 if [ "$OLDSIZE" != "$NEWSIZE" ]; then |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
70 echo 1 |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
71 else |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
72 echo 0 |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
73 fi |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
74 } |
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 update_db () { |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
77 if [ $(check_new_db) -eq 1 ]; then |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
78 mv "$NEWDB" "$OLDDB" |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
79 fi |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
80 } |
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 case $1 in |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
83 '--restart-bd') |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
84 stop_bottledash |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
85 start_bottledash |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
86 ;; |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
87 '--reload-browser') |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
88 xdo_reload_chromium |
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 '--reload') |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
91 stop_bottledash |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
92 start_bottledash |
70d50b6312e2
Initial commit of dashboardctl
Gernot Schulz <gernot@intevation.de>
parents:
diff
changeset
|
93 sleep 10 |
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 : |