-
Notifications
You must be signed in to change notification settings - Fork 47
/
restart-dashing
executable file
·106 lines (92 loc) · 3.13 KB
/
restart-dashing
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
#/******************************************************************************
# * Icinga 2 Dashing Restart Script *
# * Copyright (C) 2016-2017 Icinga Development Team (https://www.icinga.com) *
# * *
# * This program is free software; you can redistribute it and/or *
# * modify it under the terms of the GNU General Public License *
# * as published by the Free Software Foundation; either version 2 *
# * of the License, or (at your option) any later version. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU General Public License for more details. *
# * *
# * You should have received a copy of the GNU General Public License *
# * along with this program; if not, write to the Free Software Foundation *
# * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
# ******************************************************************************/
if [ -d '/usr/share/dashing-icinga2' ]; then
DASHING_PWD='/usr/share/dashing-icinga2'
else
DASHING_PWD=`pwd`
fi
DASHING_PORT=8005
DASHING_PID_FILE="tmp/pids/thin.pid"
DASHING_BIN=dashing
usage(){
cat << EOF
usage: $0 options
This script restarts the Dashing daemon.
OPTIONS:
-h Show this message
-p Port where Dashing will listen (defaults to 3030)
-P PID file path (defaults to tmp/pids/thin.pid)
-D Change to this directory before starting the daemon (defaults to current directory)
-b Path to the dashing binary (defaults to just 'dashing' from system path)
EOF
}
while getopts ":p:P:D:b:h" opt; do
case $opt in
h)
usage
exit 1
;;
p)
DASHING_PORT=$OPTARG
;;
P)
DASHING_PID_FILE=$OPTARG
;;
D)
DASHING_PWD=$OPTARG
;;
b)
DASHING_BIN=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
usage
exit 1
;;
esac
done
# ensure that dashing runs with utf8
export LANG=en_US.UTF-8
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export PATH="/usr/local/bin:$PATH"
cd $DASHING_PWD
if [ -f "$DASHING_PID_FILE" ]; then
kill -9 $(<"$DASHING_PID_FILE") > /dev/null 2>&1
rm -f $DASHING_PID_FILE
fi
$DASHING_BIN start -d -p $DASHING_PORT --pid $DASHING_PID_FILE
ERR=$?
if [ $ERR != 0 ]; then
echo "Restart failed. Bailing out."
exit $ERR
fi
# dashing might take a while to start
while [ ! -f "$DASHING_PID_FILE" ]; do
sleep 1
done
PID=$(<"$DASHING_PID_FILE")
echo "Restarted Dashing with PID $PID listening on port $DASHING_PORT."
exit $ERR