Skip to content

Commit

Permalink
add custom runscript
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticroentgen committed Jul 4, 2024
1 parent d8864ca commit 4736317
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ ENV APACHE_LOG_DIR /var/log/apache2

# Expose port 80 to access Apache
EXPOSE 80

COPY ./run.sh /run.sh
COPY ./patchman.conf /etc/apache2/conf-available/patchman.conf
RUN chmod +x /run.sh
# Use a basecommand to initialize and run Apache in the foreground
CMD ["apache2ctl", "-D", "FOREGROUND"]
CMD ["bash", "/run.sh"]
25 changes: 25 additions & 0 deletions patchman.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Define patchman_pythonpath /usr/lib/python3/dist-packages
WSGIScriptAlias /patchman ${patchman_pythonpath}/patchman/wsgi.py
WSGIPythonPath ${patchman_pythonpath}

<Directory ${patchman_pythonpath}>
<Files wsgi.py>
Require all granted
</Files>
AllowOverride All
</Directory>

Alias /patchman/static "/var/lib/patchman/static"
<Location /patchman/static>
SetHandler None
</Location>

<Directory /var/lib/patchman/static>
Require all granted
</Directory>

<Location /patchman/reports/upload>
# Add the IP addresses of your client networks/hosts here
# to allow uploading of reports
Require ip 0.0.0.0/0.0.0.0
</Location>
47 changes: 47 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
# Function to cleanly shut down processes
cleanup() {
echo "Caught Signal... terminating Apache ($APACHE_PID) and patchman ($PATCHMAN_PID) gracefully!"
# Kill the Apache process
kill -TERM $APACHE_PID
# Kill the patchman process
kill -TERM $PATCHMAN_PID
exit 0
}

# Trap SIGTERM, SIGINT and exit signals
trap cleanup SIGTERM SIGINT EXIT

echo "running migrations..."
patchman-manage migrate

echo "Starting Apache2..."
# Starts apache2ctl in the foreground
apache2ctl -D FOREGROUND &

# Apache process ID
APACHE_PID=$!

# Function to run patchman in the background periodically
run_patchman() {
while true; do
# Run patchman command
patchman -a
# Wait for 10min (600 seconds) before running again
sleep 600
done
}

echo "starting patchman processing loop..."
# Start the patchman function in the background
run_patchman &

# Capture the process ID of the background job
PATCHMAN_PID=$!

# Wait for Apache to exit
wait $APACHE_PID

# Once Apache exits, kill the background patchman job if still running
kill $PATCHMAN_PID

0 comments on commit 4736317

Please sign in to comment.