Use systemd timer for fetchmail plugin
This commit is contained in:
@@ -7,6 +7,7 @@ toolTemplates="templates_c"
|
||||
toolTemplatesLoc="$PFA_SRV_LOC/$toolTemplates"
|
||||
toolAdditionsLoc="$PFA_SRV_LOC/ADDITIONS"
|
||||
latestUrl="https://api.github.com/repos/$toolName/$toolName/releases/latest"
|
||||
fetchmailUser="fetchmail"
|
||||
fetchmailDeps="fetchmail liblockfile-simple-perl"
|
||||
|
||||
# Get script working directory
|
||||
@@ -60,32 +61,87 @@ step_3() {
|
||||
endReturn -o $? "Failed to install fetchmail"
|
||||
exe systemctl stop fetchmail
|
||||
exe systemctl disable fetchmail
|
||||
echo " [I] Create lock folder"
|
||||
exe mkdir -p "$fetchmailLockDir"
|
||||
exe chown ${fetchmail}: "$fetchmailLockDir"
|
||||
}
|
||||
fetchmailUser="fetchmail"
|
||||
fetchmailLockDir="/var/lock/fetchmail"
|
||||
|
||||
step_4_info() { echo "Configure postfixadmin to use fetchmail"; }
|
||||
step_4() {
|
||||
echo "# Create mysql config"
|
||||
echo " [$PFA_SRV_LOC/fetchmail.conf]"
|
||||
echo " # Follow instructions in $toolAdditionsLoc/fetchmail.pl"
|
||||
echo " \$db_type = 'mysql';"
|
||||
echo " \$run_dir=\"/var/lock\";"
|
||||
echo
|
||||
echo " [$toolAdditionsLoc/fetchmail.pl]"
|
||||
echo " # Change path to fetchmail.conf (see above)"
|
||||
echo
|
||||
echo " [I] Run step cron when configuration is done"
|
||||
echo " [I] Run step \"timer\" when configuration is done"
|
||||
}
|
||||
|
||||
step_6_info() { echo "Create postfixadmin fetchmail plugin cron"; }
|
||||
step_6_alias() { ALIAS="cron"; }
|
||||
step_6() {
|
||||
addConf -s "$fetchPluginCron" "$fetchPluginCronLoc"
|
||||
step_6_info() {
|
||||
echo "Create postfixadmin fetchmail systemd timer and reduce syslos entries"
|
||||
echoinfo "Needed to started after mysql service"
|
||||
}
|
||||
fetchPluginCronLoc="/etc/cron.d/fetchmailplugin"
|
||||
fetchPluginCron="*/1 * * * * fetchmail /srv/postfixadmin/ADDITIONS/fetchmail.pl > /dev/null"
|
||||
step_6_alias() { ALIAS="timer"; }
|
||||
step_6() {
|
||||
# eval needed to expand sourced configuration variables
|
||||
local localService=`eval "echo \"$fetchPluginService\""`
|
||||
|
||||
addConf -s "$localService" "$fetchPluginServiceLoc"
|
||||
addConf -s "$fetchPluginTimer" "$fetchPluginTimerLoc"
|
||||
exe systemctl enable --now ${fetchPluginServiceName}.timer
|
||||
|
||||
addConf -s "$fetchPluginRsyslog" "$fetchPluginRsyslogLoc"
|
||||
exe service rsyslog restart
|
||||
}
|
||||
fetchPluginServiceName="pfafetchmail"
|
||||
fetchPluginServiceLoc="/etc/systemd/system/${fetchPluginServiceName}.service"
|
||||
fetchPluginService="[Unit]
|
||||
Description=Postfix fetchmail plugin
|
||||
After=mysql.service
|
||||
|
||||
[Service]
|
||||
# emerg (lowest log level, only highest priority messages),
|
||||
# alert, crit, err, warning, notice, info, debug
|
||||
LogLevelMax=notice
|
||||
User=$fetchmailUser
|
||||
ExecStart=\${PFA_SRV_LOC}/ADDITIONS/fetchmail.pl >>/dev/null
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target"
|
||||
fetchPluginTimerLoc="/etc/systemd/system/${fetchPluginServiceName}.timer"
|
||||
fetchPluginTimer="[Unit]
|
||||
Description=Postfix fetchmail plugin execute every minute
|
||||
|
||||
[Timer]
|
||||
OnCalendar=minutely
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=basic.target"
|
||||
fetchPluginRsyslogLoc="/etc/rsyslog.d/31-fetchmailreduce.conf"
|
||||
fetchPluginRsyslog="if \$programname == 'systemd' and re_match(\$msg, \"Started.*fetchmail\") then stop
|
||||
if \$programname == 'systemd' and re_match(\$msg, \"fetchmail.*Succeeded\") then stop"
|
||||
|
||||
step_7_info() { echo "Create separate log file for fetchmail using rsyslog"; }
|
||||
step_7_alias() { ALIAS="newlog"; }
|
||||
step_7() {
|
||||
addConf -f "$fetchmailRsyslog" "$fetchmailRsyslogLoc"
|
||||
addConf -f "$fetchmailRotate" "$fetchmailRotateLoc"
|
||||
exe service rsyslog restart
|
||||
}
|
||||
fetchmailLogLoc="/var/log/fetchmail.log"
|
||||
fetchmailRotateLoc="/etc/logrotate.d/fetchmail"
|
||||
fetchmailRotate="$fetchmailLogLoc {
|
||||
rotate 14
|
||||
weekly
|
||||
missingok
|
||||
daily
|
||||
compress
|
||||
delaycompress
|
||||
}"
|
||||
fetchmailRsyslogLoc="/etc/rsyslog.d/30-fetchmail.conf"
|
||||
fetchmailRsyslog="if \$programname == 'fetchmail' or \$programname == 'fetchmail-all' then $fetchmailLogLoc
|
||||
& stop"
|
||||
|
||||
step_18_info() { echo "Check for updates"; }
|
||||
step_18_alias() { ALIAS="updatecheck"; }
|
||||
|
Reference in New Issue
Block a user