Skip to content

Commit 15b9405

Browse files
authored
daily maldet scan uses lock file
fixes rfxn#373
1 parent 57eb90a commit 15b9405

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

cron.daily

+29-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
33
export LMDCRON=1
44
inspath='/usr/local/maldetect'
55
intcnf="$inspath/internals/internals.conf"
6+
CRON_LOCKDIR=/var/lock/subsys
7+
CRON_LOCKFILE=${CRON_LOCKDIR}/maldet_daily_cron
68

79
if [ -f "$intcnf" ]; then
810
source $intcnf
@@ -38,6 +40,10 @@ if [ -z "$cron_prune_days" ]; then
3840
cron_prune_days=21
3941
fi
4042

43+
if [ -z "$cron_lockfile_days" ]; then
44+
cron_lockfile_days=3
45+
fi
46+
4147
if [ "$find" ]; then
4248
# prune any quarantine/session/tmp data older than 7 days
4349
tmpdirs="$tmpdir $varlibpath/sess $varlibpath/quarantine $varlibpath/pub"
@@ -46,6 +52,7 @@ if [ "$find" ]; then
4652
$find $dir -type f -mtime +${cron_prune_days} -print0 | xargs -0 rm -f >> /dev/null 2>&1
4753
fi
4854
done
55+
$find ${CRON_LOCKFILE} -type f -mtime +${cron_lockfile_days} -print0 2>/dev/null | xargs -0 rm -f >> /dev/null 2>&1
4956
fi
5057

5158
if [ "$autoupdate_version" == "1" ] || [ "$autoupdate_signatures" == "1" ]; then
@@ -67,40 +74,52 @@ fi
6774
if [ "$(ps -A --user root -o "cmd" | grep -E maldetect | grep -E inotifywait)" ]; then
6875
$inspath/maldet --monitor-report >> /dev/null 2>&1
6976
elif [ "$cron_daily_scan" == "1" ]; then
77+
(
78+
pid=$(exec sh -c 'echo "$PPID"');
79+
if ! (set -o noclobber; echo "$pid" > "${CRON_LOCKFILE}") 2> /dev/null; then
80+
exit
81+
fi
82+
83+
trap 'rm -f "${CRON_LOCKFILE}"; exit $?' INT TERM EXIT
84+
7085
if [ -d "/home/virtual" ] && [ -d "/usr/lib/opcenter" ]; then
7186
# ensim
72-
$inspath/maldet -b -r /home/virtual/?/fst/var/www/html/,/home/virtual/?/fst/home/?/public_html/ $scan_days >> /dev/null 2>&1
87+
$inspath/maldet -r /home/virtual/?/fst/var/www/html/,/home/virtual/?/fst/home/?/public_html/ $scan_days >> /dev/null 2>&1
7388
elif [ -d "/etc/psa" ] && [ -d "/var/lib/psa" ]; then
7489
# psa
75-
$inspath/maldet -b -r /var/www/vhosts/?/ $scan_days >> /dev/null 2>&1
90+
$inspath/maldet -r /var/www/vhosts/?/ $scan_days >> /dev/null 2>&1
7691
elif [ -d "/usr/local/directadmin" ]; then
7792
# DirectAdmin
78-
$inspath/maldet -b -r /home?/?/domains/?/public_html/,/var/www/html/?/ $scan_days >> /dev/null 2>&1
93+
$inspath/maldet -r /home?/?/domains/?/public_html/,/var/www/html/?/ $scan_days >> /dev/null 2>&1
7994
elif [ -d "/var/www/clients" ]; then
8095
# ISPConfig
81-
$inspath/maldet -b -r /var/www/clients/?/web?/web,/var/www/clients/?/web?/subdomains,/var/www $scan_days >> /dev/null 2>&1
96+
$inspath/maldet -r /var/www/clients/?/web?/web,/var/www/clients/?/web?/subdomains,/var/www $scan_days >> /dev/null 2>&1
8297
elif [ -d "/etc/webmin/virtual-server" ]; then
8398
# Virtualmin
84-
$inspath/maldet -b -r /home/?/public_html/,/home/?/domains/?/public_html/ $scan_days >> /dev/null 2>&1
99+
$inspath/maldet -r /home/?/public_html/,/home/?/domains/?/public_html/ $scan_days >> /dev/null 2>&1
85100
elif [ -d "/usr/local/ispmgr" ] || [ -d "/usr/local/mgr5" ]; then
86101
# ISPmanager
87-
$inspath/maldet -b -r /var/www/?/data/,/home/?/data/ $scan_days >> /dev/null 2>&1
102+
$inspath/maldet -r /var/www/?/data/,/home/?/data/ $scan_days >> /dev/null 2>&1
88103
elif [ -d "/var/customers/webs" ]; then
89104
# froxlor
90-
$inspath/maldet -b -r /var/customers/webs/ $scan_days >> /dev/null 2>&1
105+
$inspath/maldet -r /var/customers/webs/ $scan_days >> /dev/null 2>&1
91106
elif [ -d "/usr/local/vesta" ]; then
92107
# VestaCP
93-
$inspath/maldet -b -r /home/?/web/?/public_html/,/home/?/web/?/public_shtml/,/home/?/tmp/,/home/?/web/?/private/ $scan_days >> /dev/null 2>&1
108+
$inspath/maldet -r /home/?/web/?/public_html/,/home/?/web/?/public_shtml/,/home/?/tmp/,/home/?/web/?/private/ $scan_days >> /dev/null 2>&1
94109
elif [ -d "/usr/share/dtc" ]; then
95110
# DTC
96111
if [ -f /var/lib/dtc/saved_install_config ]; then
97112
. /var/lib/dtc/saved_install_config
98113
fi
99-
$inspath/maldet -b -r ${conf_hosting_path:-/var/www/sites}/?/?/subdomains/?/html/ $scan_days >> /dev/null 2>&1
114+
$inspath/maldet -r ${conf_hosting_path:-/var/www/sites}/?/?/subdomains/?/html/ $scan_days >> /dev/null 2>&1
100115
else
101116
# cpanel, interworx and other standard home/user/public_html setups
102-
$inspath/maldet -b -r /home?/?/public_html/,/var/www/html/,/usr/local/apache/htdocs/ $scan_days >> /dev/null 2>&1
117+
$inspath/maldet -r /home?/?/public_html/,/var/www/html/,/usr/local/apache/htdocs/ $scan_days >> /dev/null 2>&1
103118
fi
119+
120+
rm -f "${CRON_LOCKFILE}"
121+
trap - INT TERM EXIT
122+
) &
104123
fi
105124

106125
if [ -f "$cron_custom_exec" ]; then

0 commit comments

Comments
 (0)