Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dynamically create crontab entries based on cake output for sync servers #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ services:
- "REDIS_FQDN=redis"
- "INIT=true" # Initialze MISP, things includes, attempting to import SQL and the Files DIR
- "CRON_USER_ID=1" # The MISP user ID to run cron jobs as
# - "SYNCSERVERS=1 2 3 4" # The MISP Feed servers to sync in the cron job
# Database Configuration (And their defaults)
# - "MYSQL_HOST=db"
# - "MYSQL_USER=misp"
Expand Down
2 changes: 2 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,15 @@ ARG PHP_VER
# Requirements:
procps \
sudo \
curl \
nginx \
supervisor \
git \
cron \
openssl \
gpg-agent gpg \
ssdeep \
jq \
libfuzzy2 \
mariadb-client \
rsync \
Expand Down
33 changes: 18 additions & 15 deletions server/files/entrypoint_cron.sh
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
#!/bin/bash

sleep 30
until curl --output /dev/null --insecure --silent --head --fail https://localhost:443; do
echo 'waiting for nginx to startup to setup crontabs'
sleep 10
done

# 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
30 2 * * * www-data /var/www/MISP/app/Console/cake Server fetchFeed "$CRON_USER_ID" all >/tmp/cronlog 2>/tmp/cronlog

00 3 * * * www-data /var/www/MISP/app/Console/cake Admin updateGalaxies >/tmp/cronlog 2>/tmp/cronlog
10 3 * * * www-data /var/www/MISP/app/Console/cake Admin updateTaxonomies >/tmp/cronlog 2>/tmp/cronlog
20 3 * * * www-data /var/www/MISP/app/Console/cake Admin updateWarningLists >/tmp/cronlog 2>/tmp/cronlog
30 3 * * * www-data /var/www/MISP/app/Console/cake Admin updateNoticeLists >/tmp/cronlog 2>/tmp/cronlog
45 3 * * * www-data /var/www/MISP/app/Console/cake Admin updateObjectTemplates >/tmp/cronlog 2>/tmp/cronlog
45 3 * * * www-data /var/www/MISP/app/Console/cake Admin updateObjectTemplates 1 >/tmp/cronlog 2>/tmp/cronlog

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this "1" the same as the CRON_USER_ID a few lines up (which defaults to 1) or something entirely different?


EOF

if [ ! -z "$SYNCSERVERS" ];
then
TIME=0
for SYNCSERVER in $SYNCSERVERS
do
cat << EOF >> /etc/cron.d/misp
$TIME 0 * * * www-data /var/www/MISP/app/Console/cake Server pull "$CRON_USER_ID" "$SYNCSERVER">/tmp/cronlog 2>/tmp/cronlog
$TIME 1 * * * www-data /var/www/MISP/app/Console/cake Server push "$CRON_USER_ID" "$SYNCSERVER">/tmp/cronlog 2>/tmp/cronlog
SERVERS=$(jq -r '.servers[].id' <<<"$(/var/www/MISP/app/Console/cake Server listServers -q)")
TIME=0
for SYNCSERVER in $SERVERS; do
echo "setting up cron for sync server $SYNCSERVER"
cat <<EOF >>/etc/cron.d/misp
$TIME 0 * * * www-data /var/www/MISP/app/Console/cake Server pull "$CRON_USER_ID" "$SYNCSERVER" >/tmp/cronlog 2>/tmp/cronlog
$TIME 1 * * * www-data /var/www/MISP/app/Console/cake Server push "$CRON_USER_ID" "$SYNCSERVER" >/tmp/cronlog 2>/tmp/cronlog
EOF

((TIME+=5))
done
fi
((TIME += 5))
done

# Build a fifo buffer for the cron logs, 777 so anyone can write to it
if [[ ! -p /tmp/cronlog ]]; then
mkfifo /tmp/cronlog
mkfifo /tmp/cronlog
fi
chmod 777 /tmp/cronlog

Expand Down