This repository was archived by the owner on Aug 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcontrol.sh
More file actions
executable file
·167 lines (149 loc) · 5.08 KB
/
control.sh
File metadata and controls
executable file
·167 lines (149 loc) · 5.08 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/bash
CURL_BASE="curl http://127.0.0.1:1523"
CURL_BASE_HEADERS="curl -D - http://127.0.0.1:1523"
W_TIMEOUT=10;
PID_REGEX="^[0-9]+$"
START_SCRIPT="./start.sh"
if [ -z "$JAVA_HOME" ] ; then
export JAVA_HOME="/www/server/java/jdk"
fi
if [[ -n "$1" ]] && [[ "$1" != "start" ]] && [[ -z "$2" ]] && [[ `curl -sI http://127.0.0.1:1523 | tr -d '\r' | sed -En 's/^HTTP\/1\.1 (.*)/\1/p'` == "401 Unauthorized" ]]
then
echo " !!! Http server requires authentication, provide 'username:password' as last script argument !!! "
exit
fi
if [ -n "$2" ]
then
CURL_BASE="curl -u $2 http://127.0.0.1:1523"
fi
function startDaemon () {
DPID=`ps aux 2>/dev/null | grep "[c]om.fg.mail.smtp.Agent" 2>/dev/null | awk '{ print $2 }' 2>/dev/null`
if [ -z "$DPID" ]; then
/bin/bash $START_SCRIPT </dev/null >/dev/null 2>&1 &
echo "Application started.";
else
echo "Application is already running, you might want to restart it";
fi
}
function getStatus () {
STATUS=0;
DPID=`ps aux 2>/dev/null | grep "[c]om.fg.mail.smtp.Agent" 2>/dev/null | awk '{ print $2 }' 2>/dev/null`
AGSTATUS=`${CURL_BASE}/agent-status 2>/dev/null`
if [ $? == 0 ]; then
echo "Application running with PID=$DPID and status:"
echo "$AGSTATUS";
elif [ "$DPID" != "" ]; then
echo "Application running with PID=$DPID but not responding to status command."
else
echo "Application is not running."
fi
return $STATUS;
}
function getUnknownBounces () {
STATUS=0;
DPID=`ps aux 2>/dev/null | grep "[c]om.fg.mail.smtp.Agent" 2>/dev/null | awk '{ print $2 }' 2>/dev/null`
AGSTATUS=`${CURL_BASE}/agent-status/unknown-bounces 2>/dev/null`
if [ $? == 0 ]; then
echo "Application running with PID=$DPID and status:"
echo "$AGSTATUS";
elif [ "$DPID" != "" ]; then
echo "Application running with PID=$DPID but not responding to getUnknownBounces command."
else
echo "Application is not running."
fi
return $STATUS;
}
function restart () {
STATUS=0;
DPID=`ps aux 2>/dev/null | grep "[c]om.fg.mail.smtp.Agent" 2>/dev/null | awk '{ print $2 }' 2>/dev/null`
if [ $? == 0 ] && [[ "$DPID" =~ $PID_REGEX ]]; then
AGSTATUS=`${CURL_BASE}/agent-restart 2>/dev/null`
echo "Application is being restarted with PID=$DPID and status:"
echo "$AGSTATUS";
elif [ -z "$DPID" ]; then
echo "Application is not running. Starting now..."
startDaemon;
else
echo "Please fix restart function of control.sh script, it does not work as expected"
fi
return $STATUS;
}
function reindex () {
STATUS=0;
DPID=`ps aux 2>/dev/null | grep "[c]om.fg.mail.smtp.Agent" 2>/dev/null | awk '{ print $2 }' 2>/dev/null`
AGSTATUS=`${CURL_BASE}/agent-reindex 2>/dev/null`
if [ $? == 0 ]; then
echo "Application running with PID=$DPID and status:"
echo "$AGSTATUS";
elif [ "$DPID" != "" ]; then
echo "Application running with PID=$DPID but not responding to reindex command."
else
echo "Application is not running."
fi
return $STATUS;
}
function refreshBouncelist () {
STATUS=0;
DPID=`ps aux 2>/dev/null | grep "[c]om.fg.mail.smtp.Agent" 2>/dev/null | awk '{ print $2 }' 2>/dev/null`
AGSTATUS=`${CURL_BASE}/agent-refresh-bouncelist 2>/dev/null`
if [ $? == 0 ]; then
echo "Application running with PID=$DPID and status:"
echo "$AGSTATUS";
elif [ "$DPID" != "" ]; then
echo "Application running with PID=$DPID but not responding to refreshBouncelist command."
else
echo "Application is not running."
fi
return $STATUS;
}
function stopDaemon () {
AGSTOP=`${CURL_BASE}/agent-shutdown 2>/dev/null`
if [ $? == 0 ]; then
echo "Trying to stop Application with agent-shutdown command."
echo "Waiting ${W_TIMEOUT}s before kill."
sleep $W_TIMEOUT;
fi
DPID=`ps aux 2>/dev/null | grep "[c]om.fg.mail.smtp.Agent" 2>/dev/null | awk '{ print $2 }' 2>/dev/null`
if [ "$DPID" != "" ]; then
echo "Trying to kill app."
kill -9 $DPID
fi
echo "Application stopped."
}
case "$1" in
start)
startDaemon;
;;
stop)
stopDaemon;
;;
restart)
restart;
;;
reindex)
reindex;
;;
refreshBouncelist)
refreshBouncelist;
;;
unknownBounces)
getUnknownBounces;
;;
status)
getStatus; STATUS_RC=$?;
exit $STATUS_RC;
;;
*)
cat <<EOF
Usage: $0 (start|stop|restart|reindex|refreshBouncelist|unknownBounces|status) [user:password]
start Start app
stop Stop app
restart Restart app (for restarting http server, reloading configuration, refreshing bounce list and reindexing)
reindex Reindex logs (for refreshing bounce list and reindexing)
refreshBouncelist Refreshes list of regular expressions for bounce categorization
unknownBounces Show all unknown bounce log entries (to add corresponding regular expression to bounce list)
status Show app status
EOF
exit 1
;;
esac