-
-
Notifications
You must be signed in to change notification settings - Fork 992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create systemd file so the app can run as a Linux system daemon. #2737 #2754
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
|
||
# READ ALL STEPS BEFORE PROCEEDING | ||
# | ||
# 0) Change the daemon_directory setting in your configuration file to | ||
# /var/run/talawa-api | ||
# 1) Copy this file to one of these directories depending on your Linux version | ||
# i. RedHat variants: /usr/lib/systemd/system/ | ||
# ii. Debian/Ubuntu variants: /lib/systemd/system/ | ||
# 2) Edit the CODEROOT path to be the full path of the Talawa API's root directory | ||
# 3) Edit the TALAWA_API_CONFIGDIR path to be the full path of the Talawa API's configuration directory | ||
# This defaults to /etc/ directory of the Talawa API codebase | ||
# 4) Edit the User and Group to match the POSIX user you want the daemon | ||
# to run as. | ||
# 4a) Set appropriate permissions: | ||
# sudo chown -R talawa:talawa /etc/talawa | ||
# sudo chmod 750 /etc/talawa | ||
# 4b) If using SELinux, set the correct context: | ||
# sudo semanage fcontext -a -t bin_t "/home/talawa/talawa-api/main.py" | ||
# sudo restorecon -v /home/talawa/talawa-api/main.py | ||
# 5) Run the command "sudo systemctl daemon-reload". This needs to be run only once | ||
# 6) Run the command "sudo systemctl start talawa-api.service" to start | ||
# 7) Run the command "sudo systemctl stop talawa-api.service" to stop | ||
# 8) Run the command "sudo systemctl restart talawa-api.service" to restart | ||
# 9) Run the command "sudo systemctl enable talawa-api.service" to make | ||
# talawa-api start automatically on boot | ||
|
||
[Unit] | ||
Description=Talawa API Service | ||
After=network.target | ||
|
||
Documentation=https://github.com/talawa-api/ | ||
After=postgresql.service redis.service | ||
Requires=postgresql.service | ||
Wants=redis.service | ||
|
||
[Service] | ||
User=talawa | ||
Group=talawa | ||
|
||
Environment=CODEROOT=/home/talawa/talawa-api | ||
Environment=TALAWA_API_CONFIGDIR=/etc/talawa | ||
Environment=VIRTUAL_ENV=$CODEROOT/venv/bin | ||
Environment=PATH=$VIRTUAL_ENV:$PATH | ||
Environment=START=--start "STOP=--stop --force" "RESTART=--restart --force" | ||
EnvironmentFile=/etc/examples/linux/systemd/talawa-api.env | ||
|
||
ExecStart=${VIRTUAL_ENV}/python3 ${CODEROOT}/main.py ${START} | ||
ExecStop=${VIRTUAL_ENV}/python3 ${CODEROOT}/main.py ${STOP} | ||
ExecReload=${VIRTUAL_ENV}/python3 ${CODEROOT}/main.py ${RESTART} | ||
Comment on lines
+47
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification The systemd service file references a non-existent main.py script The verification reveals that
🔗 Analysis chainVerify main.py supports the specified command-line arguments Let's verify that the main.py script exists and supports the specified command-line arguments (--start, --stop, --restart). 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify main.py exists and supports the required command-line arguments
# Check if main.py exists
echo "Checking for main.py..."
if ! fd "main.py$" ; then
echo "Error: main.py not found"
exit 1
fi
# Check for command-line argument handling
echo "Checking command-line argument handling..."
rg -A 5 "argparse|ArgumentParser|add_argument" "main.py" || echo "Warning: No argument parsing found in main.py"
# Look for start/stop/restart handling
echo "Checking start/stop/restart handling..."
rg -i "def (start|stop|restart)" "main.py" || echo "Warning: No start/stop/restart functions found in main.py"
Length of output: 678 |
||
|
||
RemainAfterExit=yes | ||
GuessMainPID=yes | ||
Type=simple | ||
RuntimeDirectory=talawa | ||
|
||
# Restart policy | ||
Restart=always | ||
RestartSec=3 | ||
|
||
# Security settings | ||
NoNewPrivileges=yes | ||
PrivateTmp=yes | ||
ProtectSystem=full | ||
ProtectHome=read-only | ||
|
||
# Resource limits | ||
LimitNOFILE=65535 | ||
LimitNPROC=4096 | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CODEROOT=/home/talawa/talawa-api | ||
TALAWA_API_CONFIGDIR=/etc/talawa | ||
VIRTUAL_ENV=${CODEROOT}/venv/bin | ||
PATH=${VIRTUAL_ENV}:${PATH} | ||
START=--start | ||
STOP=--stop --force | ||
RESTART=--restart --force |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add essential service dependencies
The Unit section should include additional dependencies and documentation:
This ensures proper service startup order and documents the service's dependencies.
📝 Committable suggestion