diff --git a/examples/linux/systemd/systemd-talawa-api.service b/examples/linux/systemd/systemd-talawa-api.service new file mode 100644 index 0000000000..7306014de3 --- /dev/null +++ b/examples/linux/systemd/systemd-talawa-api.service @@ -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} + +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 diff --git a/examples/linux/systemd/talawa-api.env b/examples/linux/systemd/talawa-api.env new file mode 100644 index 0000000000..afc3c85a9f --- /dev/null +++ b/examples/linux/systemd/talawa-api.env @@ -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 \ No newline at end of file