I'm running a Flask application on a server via nginx. I want to create a systemd file and here's what I have:[Unit]Description=my123 websiteAfter=syslog.targetRequires=postgresql.service[Service]ExecStart=/home/user_123/my_web_app/run.py &ExecStop=Restart=on-abortWorkingDirectory=/home/user_123/my_web_app/SyslogIdentifier=my_web_appUser=user_123[Install]WantedBy=multi-user.targetLocally I run it as ./run.py. Now, what should I have in ExecStart and ExecStop? I think ExecStart is correct because I have the & in it. But how about ExecStop?
Creating a systemd service for Flask via nginx
ubuntu;systemd;python
No, you should never add & to ExecStart.  That will make systemd think that your unit is the process doing the forking.  Also, you do not need ExecStop for a service that understands SIGTERM (flask's built-in webserver does), systemd knows where to send the signal.i.e. systemd tracks the PID that ExecStart started at and then knows where to send SIGTERM when you ask to terminate the process.(A unit type= can make forks a little more complicated than that.  But the default unit type= considers that there are no forks.)ExtraRunning the built-in flask server behind Nginx will render you very vulnerable to even a trivial DoS attack.  The flask built-in server is not meant for production use.  With Nginx you should be using something like uWSGI.Flask docs have a section on uwsgi, and you can map the command line easily to edit uWSGI configuration file options.  And uWSGI docs have a section on systemd.  And you really should be using systemd to start a real webserver akin of uWSGI, not the flask built-in one.