1 #!/bin/bash 2 # Script to update the KISSmo Perl repository and restart the application 3 4 # Navigate to the application directory. Exit if the directory is not found. 5 cd /app || { echo "$(date): Error: /app directory not found. Aborting update." >> /var/log/cron.log; exit 1; } 6 7 echo "$(date): Starting KISSmo Perl update..." >> /var/log/cron.log 8 9 # Pull the latest changes from the Git repository 10 git pull 11 if [ $? -ne 0 ]; then 12 echo "$(date): Git pull failed. Aborting update." >> /var/log/cron.log 13 exit 1 14 fi 15 echo "$(date): Git repository updated successfully." >> /var/log/cron.log 16 17 # Find the PID of the running KISSmo Perl process and kill it. 18 # We use 'pgrep -f' to match the full command line of the perl process. 19 PIDS=$(pgrep -f "perl paste.pl daemon -m production -l http://0.0.0.0:7878") 20 if [ -n "$PIDS" ]; then 21 echo "$(date): Found running KISSmo Perl processes: $PIDS. Killing them..." >> /var/log/cron.log 22 kill $PIDS 23 # Give the process some time to shut down gracefully 24 sleep 5 25 else 26 echo "$(date): No running KISSmo Perl processes found to kill." >> /var/log/cron.log 27 fi 28 29 # Start the application again in daemon mode 30 echo "$(date): Restarting KISSmo Perl application..." >> /var/log/cron.log 31 perl paste.pl daemon -m production -l http://0.0.0.0:7878 32 if [ $? -ne 0 ]; then 33 echo "$(date): Failed to restart KISSmo Perl application." >> /var/log/cron.log 34 exit 1 35 fi 36 echo "$(date): KISSmo Perl restarted successfully." >> /var/log/cron.log