I'll create a shell script to safely stop the API service.
Save this script as stop_api_service.sh
in the same directory as your other scripts. Here's how to use it:
- Make it executable:
chmod +x stop_api_service.sh
- To stop the service:
./stop_api_service.sh
- To stop the service AND prevent it from starting on next reboot:
./stop_api_service.sh --disable-autostart
The script will:
- Check if the API service is running
- Send a graceful termination signal (Ctrl+C) to your Python process
- Wait a moment for clean shutdown
- Kill the tmux session
- Optionally remove it from crontab if you use the --disable-autostart flag
If you ever need to check the status before stopping:
tmux ls
This will show you if the api_service session is running.
Would you like me to explain any part of this script in more detail?