#!/bin/bash # Script to update the KISSmo Perl repository and restart the application # Navigate to the application directory. Exit if the directory is not found. cd /app || { echo "$(date): Error: /app directory not found. Aborting update." >> /var/log/cron.log; exit 1; } echo "$(date): Starting KISSmo Perl update..." >> /var/log/cron.log # Pull the latest changes from the Git repository git pull if [ $? -ne 0 ]; then echo "$(date): Git pull failed. Aborting update." >> /var/log/cron.log exit 1 fi echo "$(date): Git repository updated successfully." >> /var/log/cron.log # Find the PID of the running KISSmo Perl process and kill it. # We use 'pgrep -f' to match the full command line of the perl process. PIDS=$(pgrep -f "perl paste.pl daemon -m production -l http://0.0.0.0:7878") if [ -n "$PIDS" ]; then echo "$(date): Found running KISSmo Perl processes: $PIDS. Killing them..." >> /var/log/cron.log kill $PIDS # Give the process some time to shut down gracefully sleep 5 else echo "$(date): No running KISSmo Perl processes found to kill." >> /var/log/cron.log fi # Start the application again in daemon mode echo "$(date): Restarting KISSmo Perl application..." >> /var/log/cron.log perl paste.pl daemon -m production -l http://0.0.0.0:7878 if [ $? -ne 0 ]; then echo "$(date): Failed to restart KISSmo Perl application." >> /var/log/cron.log exit 1 fi echo "$(date): KISSmo Perl restarted successfully." >> /var/log/cron.log