• Create New flaskapp.service File Under /etc/systemd/system/ Directory

[root@pythonsvr01 ~]# vi /etc/systemd/system/flaskapp.service
[Unit]
Description=Flask Python Application Container
After=network.target

[Service]
Type=idle

Environment=CONFIGURATION_SETUP=config.ProductionConfig
Environment=FLASK_ENV=production

ExecStart=/bin/bash -c '/usr/bin/python3.6 /opt/flaskapp/app.py'
ExecStop=/bin/kill -15 $MAINPID

User=root
Group=root
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target

  • Reload Daemon

[root@pythonsvr01 ~ ]# systemctl daemon-reload

  • Enable and Start Service

[root@pythonsvr01 ~ ]# systemctl enable flaskapp
Created symlink /etc/systemd/system/multi-user.target.wants/flaskapp.service → /etc/systemd/system/flaskapp.service.
[root@pythonsvr01 ~ ]# systemctl start flaskapp

[root@pythonsvr01 ~ ]# systemctl status analytics
flaskapp.service - Flask Python Application Container
   Loaded: loaded (/etc/systemd/system/flaskapp.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2022-12-08 14:52:25 IST; 1min 55s ago
 Main PID: 3098001 (python3.6)
    Tasks: 4 (limit: 100506)
   Memory: 54.4M
   CGroup: /system.slice/flaskapp.service
           └─3098001 /usr/bin/python3.6 /opt/flaskapp/app.py

Dec 08 14:52:26 pythonsvr01 bash[3098001]:  * Serving Flask app 'app.app' (lazy loading)
Dec 08 14:52:26 pythonsvr01 bash[3098001]:  * Environment: production
Dec 08 14:52:26 pythonsvr01 bash[3098001]:    WARNING: This is a development server. Do not use it in a pro>
Dec 08 14:52:26 pythonsvr01 bash[3098001]:    Use a production WSGI server instead.
Dec 08 14:52:26 pythonsvr01 bash[3098001]:  * Debug mode: off
Dec 08 14:52:26 pythonsvr01 bash[3098001]: INFO:werkzeug: * Running on http://192.168.10.1:8080/ (Press C>
[root@pythonsvr01 ~ ]#

Technology