Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23247

Problems with starting waitress-serve via systemd service

$
0
0

Project Environment

I have a Flask-based web service I can start from the command line. The project environment looks like this:

BASEDIR/    startMyService.sh    |-venv/        |-/bin        |...    |-/WebService...    |-Flask-related directories

I am providing a virtual environment to make it run ($BASEDIR is the path, where the project environment is located):

sudo python -m venv ./venvsource $BASEDIR/venv/bin/activatewaitress-serve --port=8080 --call 'WebService:create_app'

Note: when doing this, I see, that the venv has been activated by the (venv) prefixing the command line.

Shell Script for Starting WebService

I wrapped the commands above in a shell script startMyService.sh with the following code ($BASEDIR is the directory where the script is located):

#!/bin/bash# activate venv located in same directory as this filepython -m venv $BASEDIR/venvsource $BASEDIR/venv/bin/activatepip install waitresspip install flaskpip install ... whatever# re-install the web application provided as wheel$BASEDIR/venv/bin/pip3 uninstall myapp --yes$BASEDIR/venv/bin/pip3  install $BASEDIR/dist/myapp-0.1.0-py3-none-any.whl --force-reinstall# find already running instances of the service and kill themPROCESSID=`ps aux | grep "WebService:create_app" | grep -v "grep" | awk '{print $2}'`if [[ $PROCESSID != "" ]]then    echo "killing existing instances of WebService with PID $PROCESSID"    kill -9 $PROCESSIDfi# start webserver in the backgroundecho "Starting webService..."waitress-serve --port=8080 --call 'WebService:create_app'

Systemd Service causing Problems

Now I would like to make a systemd service from that script. Currently, the .service-File looks like this:

[Unit]Description=My web applicationDocumentation=some url[Service]PIDFile=/run/pidfile.pidType=simpleExecStart=theApplicationDirectory/startMyService.shExecStop=/bin/kill -9 $MAINPID[Install]WantedBy=default.target

When I start the service via sudo systemctl start myservice.service the service ends up in status "dead"/incative. journalctl show some indication:

...Starting status webpage in testing modeMay 06 11:33:00 servername startMyService.sh[726211]: Error: Bad module 'WebViewer'May 06 11:33:00 servername startMyService.sh[726211]: Usage:May 06 11:33:00 servername startMyService.sh[726211]:     waitress-serve [OPTS] MODULE:OBJECT

To me it seems that the activation of the virtual environment in the shell script does not happen and the service wants to start with the default Python instead of the venv.


Viewing all articles
Browse latest Browse all 23247

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>