File: //lib/cgi-bin/eventplanner_restart.sh
#!/bin/bash
# Output the content type for CGI
echo "Content-type: text/plain"
echo ""
# Set the port number
PORT=5055
# Find the PID of the process running on the specified port
PID=$(sudo /usr/bin/lsof -ti tcp:$PORT)
# If a process is found, kill it
if [ -n "$PID" ]; then
echo "Killing process on port $PORT with PID: $PID"
# Kill the process
sudo /usr/bin/kill -9 $PID
if [ $? -eq 0 ]; then
echo "Process with PID $PID killed successfully."
else
echo "Failed to kill process with PID $PID."
exit 1
fi
else
echo "No process found on port $PORT."
exit 1
fi
# Restart the app using `nohup` and http-server
echo "Restarting the static server using http-server..."
# Assuming your index.html is in the current directory
nohup http-server /var/www/html/eventplanner/backend/index.js -p $PORT > /var/www/html/eventplanner/logfile.log 2>&1 &
# Output success message
echo "App restarted successfully using http-server."