-
Notifications
You must be signed in to change notification settings - Fork 0
/
exim-restart.sh
executable file
·85 lines (70 loc) · 2.13 KB
/
exim-restart.sh
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
#!/bin/bash
echo "Reloading Exim4 configuration files ..."
echo
SYSD_UNITNAME_EXIM4="exim4.service"
EXIM4_CONF_FILENAME="exim4.conf"
ETC_EXIM4_CONF_DIRSPEC="/etc/exim4"
ETC_EXIM4_CONF_FILESPEC="${ETC_EXIM4_CONF_DIRSPEC}/$EXIM4_CONF_FILENAME"
EXIM4_CONF_AUTOGEN_FILENAME="config.autogenerated"
VARLIB_EXIM4_CONF_DIRSPEC="/var/lib/exim4"
VARLIB_EXIM4_CONF_FILESPEC="${VARLIB_EXIM4_CONF_DIRSPEC}/$EXIM4_CONF_AUTOGEN_FILENAME"
# Decide which Exim4 config file mode is used:
# Plain ol' exim4.conf
# Debian standalone
# Debian split-file
if [ -f "$ETC_EXIM4_CONF_FILESPEC" ]; then
# Original Exim4 setup
EXIM4_CONF_FILESPEC="$ETC_EXIM4_CONF_FILESPEC"
else
# Both Debian standalone and Debian split-file
EXIM4_CONF_FILESPEC="$VARLIB_EXIM4_CONF_FILESPEC"
fi
EXIM4_LOG_PANIC="/var/log/exim4/paniclog"
if [ "$USER" != 'root' ]; then
echo "User $USER cannot run this script; go to 'root' account."
exit 1
fi
# Pre-emptive check
if [ -s "$EXIM4_LOG_PANIC" ]; then
tail "$EXIM4_LOG_PANIC"
echo "Panic Log: $EXIM4_LOG_PANIC"
echo "Review then empty panic file before starting Exim4; aborted."
exit 1
fi
echo "Merging config settings into $EXIM4_CONF_FILESPEC ..."
update-exim4.conf -v
retsts=$?
if [ $retsts -ne 0 ]; then
echo "Error code $retsts in update-exim4.conf"
exit $retsts
fi
echo
# Syntax checking Exim4
echo "Checking for valid syntax in $EXIM4_CONF_FILESPEC ..."
exim4 -bV -C "$EXIM4_CONF_FILESPEC"
retsts=$?
if [ $retsts -ne 0 ]; then
echo "Error code $retsts in Exim4 syntax check."
exit $retsts
fi
echo
echo "Stopping $SYSD_UNITNAME_EXIM4 systemd unit ..."
systemctl stop "$SYSD_UNITNAME_EXIM4"
retsts=$?
if [ $retsts -ne 0 ]; then
echo "Error code $retsts in 'systemctl stop $SYSD_UNITNAME_EXIM4'"
exit $retsts
fi
echo "Starting $SYSD_UNITNAME_EXIM4 systemd unit ..."
systemctl start "$SYSD_UNITNAME_EXIM4"
retsts=$?
if [ $retsts -ne 0 ]; then
echo "Error code $retsts in 'systemctl start $SYSD_UNITNAME_EXIM4'"
exit $retsts
fi
systemctl status "$SYSD_UNITNAME_EXIM4" | fold
echo
echo "Successfully restarted:"
echo " Systemd Unit: $SYSD_UNITNAME_EXIM4"
echo " Config file : $EXIM4_CONF_FILESPEC"
echo "Done."