Difference between revisions of "Pubapps Systemd Use"
Moskalenko (talk | contribs) (→Use) |
Moskalenko (talk | contribs) (→Use) |
||
Line 34: | Line 34: | ||
* Enable user linger mode to avoid having your application be shut down when you log out: | * Enable user linger mode to avoid having your application be shut down when you log out: | ||
− | loginctl enable-linger | + | loginctl enable-linger PROJECTUSER |
* Manage the application with | * Manage the application with | ||
** Initial load of the configuration to enable the service | ** Initial load of the configuration to enable the service |
Revision as of 15:42, 18 July 2024
back to Web_Application_Hosting
Introduction
If one or more of your web applications hosted on pubapps infrastructure are architected to run on the webserver you need to have two copies of the app running on every pubweb[1,2] server to account for the HA (High Availability) configuration of the pubapps infrastructure where a secondary pubweb webserver will take over if there is an issue with the main webserver. To make sure your web applications are running after an HA failover or start when a server in pubapps infrastructure is restarted we encourage you to use a systemd script, which can automate the start/stop/restart process. This help article should help you create and use such a script.
Configuration
Systemd has two modes of operation - system-wide, which requires the service scripts to be in a system location and operated by root and a user mode. You will be using the user mode.
- Create a user systemd directory under your /pubapps/PROJECT/ $HOME directory in pubapps
mkdir -p .config/systemd/user/
- Add a service script for the application, e.g. ~/.config/systemd/user/projprod.service or projdev.service
Script
Example systemd script
[Unit] Description=MyProject (Production) After=network.target [Service] Type=simple WorkingDirectory=/pubapps/myinstance/myproject/prod/ ExecStart=/pubapps/myinstance/myproject/prod/conda/bin/python3 run/runserver.py TimeoutSec=30 RestartSec=15s Restart=always [Install] WantedBy=multi-user.target
Use
- Enable user linger mode to avoid having your application be shut down when you log out:
loginctl enable-linger PROJECTUSER
- Manage the application with
- Initial load of the configuration to enable the service
systemctl --user enable projprod
- Reload configuration (after every change of the systemd service script)
systemctl --user daemon-reload
- Start service
systemctl --user start projprod
- Stop service
systemctl --user stop projprod
- Restart service
systemctl --user restart projprod
- Check if the service is running
systemctl --user status projprod
- Start the application on pubweb[1,2] servers.
For additional information search web for 'systemd user mode'. E.g. https://wiki.archlinux.org/title/Systemd/User