I'm working on a script that will periodically shutdown the programs in our environment. The main script is a python program that will check to see if a service has made a database entry in the last few days. If not, it will turn it off with pm2 stop. I've already established that this works, running python from the command line. The issue starts when I try to call the script from pm2. There is a spike in activity, but nothing happens. The script just completes with no services turned off, and no log output. PM2 ls shows the service as stopped, as though it ran successfully.
This is what I have in pm2_config.json:
{"apps" : [ {"name" : "daily_shutdown","script" : "shutdownservice.py","interpreter": "python","cron_restart": "0 2 * * *","autorestart": false,"pid_file": "~/daily_shutdown/bin/daily_shutdown.pid","out_file": "~/daily_shutdown/bin/daily_shutdown.log","error_file": "~/daily_shutdown/bin/daily_shutdown.log","log_date_format" : "YYYY-MM-DD HH:mm:ss" } ]}
The start.sh script simply runs it:
#!/bin/bashsource deactivatesource activate shutdown_envpm2 start $HOME/daily_shutdown/bin/pm2_config.json#I have also tried 'pm2 start shutdownservice.py --name shutdownservice --interpreter python --cron '0 2 * * *' --no-autorestart'
This is a sanitized version of main code for shutdownservice.py. As I said, we have tested this and it runs successfully on its own:
def main(env, serviceList, whiteList): for service in serviceList: logger.info("Checking activity for: ") logger.info(service) logger.info(env) if service not in whiteList: logger.info("Shutting down " + service) call('pm2 stop /'+service+'/', shell=True)