I would like to refer to this question because I am sure that someone will mark this as a duplicate.
I am not looking for another link to supervisord . I am sure that this is great and thatβs all, but node PM2 has the functions that I need and is simpler to implement and test them.
Manual start
During prototyping, I created a virtual environment called "p3env". At the top of each script, I place the bash directive:
This allows me to execute every script in the directory using this particular python environment, without having to activate it. This is very convenient and useful, and the python script works well when I start it manually.
It should be clear to me what I mean when I say "start it by hand." My script is called 'strain_to_db.py'. When I run it manually, I am in the shell via ssh:
./strain_to_db.py
This gets everything I need to work.
PM2 Start
Transition from relative to absolute paths
To get pm2 to work, I started with:
pm2 start ./strain_to_db.py
Interpreter task
Obviously, pm2 ignores the directive at the top of the python script and tries to execute using the global "python". No problem, I can specify the interpreter:
pm2 start ./strain_to_db.py
No dice. Again, perhaps try more absolute paths:
pm2 start /home/ubuntu/db_if/strain_to_db.py
Running a script as a command line option
Now I'm upset. I try different tactics. I am trying to run python executable on the command line using:
/home/ubuntu/db_if/p3env/bin/python /home/ubuntu/db_if/strain_to_db.py
This works fine when pm2 is not involved. When I try to pass this to pm2 using the command line argument style:
pm2 start /home/ubuntu/db_if/p3env/bin/python
Disappointment
The same mistakes. The error is always "cannot import pymysql", which is installed only in a virtual environment.
I'm not sure where else to go with this. I have several scripts that I want to add to the pm2 runtime monitor, but I cannot get them to start and run correctly.