mirror of https://github.com/MISP/misp-docker
Fix how cron are launched and managed (#8)
Changes: - cron is now launched with the -l option - pipe cron/tail is now a fifo so sigterm is handled properly Co-authored-by: Stefano Ortolani <ortolanis@vmware.com>pull/1/head
parent
bc512da318
commit
231d099a9f
|
@ -1,25 +1,43 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
term_pipe_procs() {
|
||||||
|
echo "Cron entrypoint caught SIGTERM signal!"
|
||||||
|
kill -TERM "$p1_pid" 2>/dev/null
|
||||||
|
kill -TERM "$p2_pid" 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
trap term_pipe_procs SIGTERM
|
||||||
|
|
||||||
# Create the misp cron tab
|
# Create the misp cron tab
|
||||||
cat << EOF > /etc/cron.d/misp
|
cat << EOF > /etc/cron.d/misp
|
||||||
20 2 * * * www-data /var/www/MISP/app/Console/cake Server cacheFeed "$CRON_USER_ID" all >/tmp/cronlog 2>/tmp/cronlog
|
20 2 * * * www-data /var/www/MISP/app/Console/cake Server cacheFeed "$CRON_USER_ID" all > /tmp/cronlog 2>&1
|
||||||
30 2 * * * www-data /var/www/MISP/app/Console/cake Server fetchFeed "$CRON_USER_ID" all >/tmp/cronlog 2>/tmp/cronlog
|
30 2 * * * www-data /var/www/MISP/app/Console/cake Server fetchFeed "$CRON_USER_ID" all > /tmp/cronlog 2>&1
|
||||||
|
|
||||||
0 0 * * * www-data /var/www/MISP/app/Console/cake Server pullAll "$CRON_USER_ID" >/tmp/cronlog 2>/tmp/cronlog
|
0 0 * * * www-data /var/www/MISP/app/Console/cake Server pullAll "$CRON_USER_ID" > /tmp/cronlog 2>&1
|
||||||
0 1 * * * www-data /var/www/MISP/app/Console/cake Server pushAll "$CRON_USER_ID" >/tmp/cronlog 2>/tmp/cronlog
|
0 1 * * * www-data /var/www/MISP/app/Console/cake Server pushAll "$CRON_USER_ID" > /tmp/cronlog 2>&1
|
||||||
|
|
||||||
00 3 * * * www-data /var/www/MISP/app/Console/cake Admin updateGalaxies >/tmp/cronlog 2>/tmp/cronlog
|
00 3 * * * www-data /var/www/MISP/app/Console/cake Admin updateGalaxies > /tmp/cronlog 2>&1
|
||||||
10 3 * * * www-data /var/www/MISP/app/Console/cake Admin updateTaxonomies >/tmp/cronlog 2>/tmp/cronlog
|
10 3 * * * www-data /var/www/MISP/app/Console/cake Admin updateTaxonomies > /tmp/cronlog 2>&1
|
||||||
20 3 * * * www-data /var/www/MISP/app/Console/cake Admin updateWarningLists >/tmp/cronlog 2>/tmp/cronlog
|
20 3 * * * www-data /var/www/MISP/app/Console/cake Admin updateWarningLists > /tmp/cronlog 2>&1
|
||||||
30 3 * * * www-data /var/www/MISP/app/Console/cake Admin updateNoticeLists >/tmp/cronlog 2>/tmp/cronlog
|
30 3 * * * www-data /var/www/MISP/app/Console/cake Admin updateNoticeLists > /tmp/cronlog 2>&1
|
||||||
45 3 * * * www-data /var/www/MISP/app/Console/cake Admin updateObjectTemplates "$CRON_USER_ID" >/tmp/cronlog 2>/tmp/cronlog
|
45 3 * * * www-data /var/www/MISP/app/Console/cake Admin updateObjectTemplates "$CRON_USER_ID" > /tmp/cronlog 2>&1
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Build a fifo buffer for the cron logs, 777 so anyone can write to it
|
# Build a fifo buffer for the cron logs, 777 so anyone can write to it
|
||||||
if [[ ! -p /tmp/cronlog ]]; then
|
if [[ ! -p /tmp/cronlog ]]; then
|
||||||
mkfifo /tmp/cronlog
|
mkfifo -m 777 /tmp/cronlog
|
||||||
fi
|
fi
|
||||||
chmod 777 /tmp/cronlog
|
|
||||||
|
|
||||||
cron -f | tail -f /tmp/cronlog
|
# Build another fifo for the cron pipe
|
||||||
|
if [[ ! -p /tmp/cronpipe ]]; then
|
||||||
|
mkfifo /tmp/cronpipe
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Execute the cron pipe
|
||||||
|
cron -l -f > /tmp/cronpipe & p1_pid=$!
|
||||||
|
tail -f /tmp/cronlog < /tmp/cronpipe & p2_pid=$!
|
||||||
|
|
||||||
|
# Wait for both processes of the cron pipe
|
||||||
|
wait "$p2_pid"
|
||||||
|
wait "$p1_pid"
|
||||||
|
|
Loading…
Reference in New Issue