-
Notifications
You must be signed in to change notification settings - Fork 1
/
hcont
87 lines (74 loc) · 2.01 KB
/
hcont
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
#!/usr/bin/env bash
IN_LOCATION="/opt/haraka/haraka-in"
OUT_LOCATION="/opt/haraka/haraka-out"
INPID_LOCATION="/var/run/haraka-in.pid"
OUTPID_LOCATION="/var/run/haraka-out.pid"
INPID=
OUTPID=
getPids() {
INPID="$(cat $INPID_LOCATION 2>/dev/null)"
OUTPID="$(cat $OUTPID_LOCATION 2>/dev/null)"
}
getPids
isRoot() {
[[ "$(whoami)" == "root" ]] && return 0
return 1
}
exitNotRoot() {
echo "You need to be root for that!"
exit 1;
}
stats() {
local inStat="$(ps aux | grep $INPID 2>/dev/null| grep -v grep)"
local outStat="$(ps aux | grep $OUTPID 2>/dev/null| grep -v grep)"
echo "Haraka In --------"
echo "$inStat"
echo
echo "Haraka Out -------"
echo "$outStat"
}
killPid() {
isRoot || exitNotRoot
if [[ "$1" == "in" ]]; then
kill "$INPID"
rm -rf "$INPID_LOCATION"
elif [[ "$1" == "out" ]]; then
kill "$OUTPID"
rm -rf "$OUTPID_LOCATION"
elif [[ "$1" == "both" ]]; then
killPid "in"
killPid "out"
fi
}
startHaraka() {
isRoot || exitNotRoot
if [[ "$1" == "in" ]]; then
haraka -c "$IN_LOCATION"
elif [[ "$1" == "out" ]]; then
haraka -c "$OUT_LOCATION"
elif [[ "$1" == "both" ]]; then
startHaraka "in"
startHaraka "out"
fi
}
restartHaraka() {
isRoot || exitNotRoot
killPid "$1"
sleep 5
startHaraka "$1"
}
main() {
if [[ "$1" == "stats" ]]; then
stats
elif [[ "$2" != "in" && "$2" != "out" && "$2" != "both" ]]; then
echo "You need to specify in or out! (or 'both')"
return 1
elif [[ "$1" == "kill" ]]; then
killPid "$2"
elif [[ "$1" == "start" ]]; then
startHaraka "$2"
elif [[ "$1" == "restart" ]]; then
restartHaraka "$2"
fi
}
main $@