pythonubuntudockerdaemonstart-stop-daemon

sbin/start-stop-daemon not able to start python - ubuntu docker container


I have a simple python script which I want to start a daemon-service in background in docker container

/sbin/start-stop-daemon --start  --user root --make-pidfile --pidfile /var/lock/subsys/my-application.pid --exec 'python /opt/app/uc/monitor/bin/my-application.py'

when I execute this command in a shell I get

/sbin/start-stop-daemon: unable to stat //python /opt/app/uc/monitor/bin/my-application.py (No such file or directory)

However when execute just the below command in shell it works

python /opt/app/uc/monitor/bin/my-application.py 

I'm sure the python is installed and all the links have been setup.

Thanks for the help


Solution

  • That error message implies that start-stop-daemon is looking for a file to open (the stat operation is a check before it opens the file) and treating your 'python ... ' argument as if it was a file.

    See this example which confirms this. You may need to read the man page for start-stop-daemon, for your Ubuntu version, to check what a valid command would be for your setup.

    Simplest solution is probably to create a shell script (say /opt/app/uc/monitor/bin/run-my-application.sh), and put this into it:

    #!/bin/bash
    python /opt/app/uc/monitor/bin/my-application.py
    

    Be sure to do chmod +x on this file. If python is not found, use which python to find the path to python and use that in the script.

    Now try:

    /sbin/start-stop-daemon --start  --user root --make-pidfile --pidfile /var/lock/subsys/my-application.pid --exec '/opt/app/uc/monitor/bin/run-my-application.sh'