From 2c61c48ff15b9c967abe35730c215a11ab410add Mon Sep 17 00:00:00 2001 From: Sahitya Chandra Date: Fri, 3 Jan 2025 14:49:27 +0530 Subject: [PATCH] talawa_admin.service file added --- examples/linux/Daemon_Service_Setup.md | 68 +++++++++++++++++++++ examples/linux/systemd/talawa_admin.service | 47 ++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 examples/linux/Daemon_Service_Setup.md create mode 100644 examples/linux/systemd/talawa_admin.service diff --git a/examples/linux/Daemon_Service_Setup.md b/examples/linux/Daemon_Service_Setup.md new file mode 100644 index 0000000000..51344be6b5 --- /dev/null +++ b/examples/linux/Daemon_Service_Setup.md @@ -0,0 +1,68 @@ + +# Talawa-Admin Service Setup Guide + +This guide outlines the steps to set up and manage the Talawa-Admin service on a Linux server using `systemd`. + +### Prerequisites + +- Ensure **Node.js** and **npm** are correctly installed and available for the specified user and group. +- It’s recommended to use **nvm** (Node Version Manager) for better management of different Node.js versions. + +--- + +### Service Configuration + +#### 1. **Copy the `talawa_admin.service` file** + - Place the `talawa_admin.service` file in the appropriate systemd directory based on your Linux distribution: + - For most distributions: `/etc/systemd/system/` + - For systems using `systemd`, this will be the default directory. + +#### 2. **Verify the CODEROOT Path** + - Ensure that the `CODEROOT` environment variable matches the absolute path to the Talawa-Admin code directory. + +#### 3. **Set the Correct Working Directory** + - Always use the absolute path for the `WorkingDirectory`. Do **not** use `$CODEROOT` in the `WorkingDirectory` field. + +#### 4. **Ensure the `.env` File Exists** + - Verify that the path in the `EnvironmentFile` line points to a valid `.env` file located in the root directory of the Talawa-Admin repository. + +#### 5. **Adjust User and Group** + - Modify the `User` and `Group` settings to match the user account intended to run the service. + +--- + +### Steps to Enable and Manage the Service + +1. **Reload the systemd daemon** to apply changes: + ```bash + sudo systemctl daemon-reload + ``` + +2. **Start the Talawa-Admin Service**: + ```bash + sudo systemctl start talawa_admin.service + ``` + +3. **Stop the Talawa-Admin Service**: + ```bash + sudo systemctl stop talawa_admin.service + ``` + +4. **Enable the Service to Start on Boot**: + ```bash + sudo systemctl enable talawa_admin.service + ``` + +--- + +### Troubleshooting + +- If you encounter any issues, you can check the status and logs of the service: + ```bash + sudo systemctl status talawa_admin.service + sudo journalctl -u talawa_admin.service + ``` + +--- + +By following these steps, you can set up and manage the Talawa-Admin service efficiently on your Linux server. \ No newline at end of file diff --git a/examples/linux/systemd/talawa_admin.service b/examples/linux/systemd/talawa_admin.service new file mode 100644 index 0000000000..e3c695943a --- /dev/null +++ b/examples/linux/systemd/talawa_admin.service @@ -0,0 +1,47 @@ + +################################################################################ +# +# READ ALL STEPS BEFORE PROCEEDING +# +# 0) Ensure that Node.js and npm are correctly installed and available for the +# specified user and group. +# Use nvm for better interaction with different node versions. +# 1) Place this file in the appropriate systemd directory based on your Linux +# distribution, e.g., /etc/systemd/system/. +# 2) Verify the CODEROOT path matches the Talawa-Admin code directory. +# 3) Always add the absolute path of talawa-admin directory to WorkingDirectory don't use $CODEROOT. +# 4) Ensure the EnvironmentFile path points to a valid .env file for the service. +# 5) Adjust the User and Group to match the user account intended to run the service. +# 6) Run the command "sudo systemctl daemon-reload" after saving changes. +# 7) Use "sudo systemctl start talawa_admin.service" to start the service. +# 8) Use "sudo systemctl stop talawa_admin.service" to stop the service. +# 9) Use "sudo systemctl enable talawa_admin.service" to start the service on boot. +# +################################################################################ + +[Unit] +Description=Talawa-Admin Service +After=network.target + +[Service] +User=talawa +Group=talawa +Environment=CODEROOT=path/to/your/talawa-admin + +# Absolute path is needed for working directory +WorkingDirectory=/path/to/your/talawa-admin + +EnvironmentFile=/path/to/your/talawa-admin/.env + +################################################################################ +# No need to edit anything below here +################################################################################ + +ExecStart=/bin/bash -c "source /path/to/your/.nvm/nvm.sh && nvm use default && npm run serve" +Restart=on-failure +RemainAfterExit=yes +Type=simple +RuntimeDirectory=talawa-admin + +[Install] +WantedBy=multi-user.target \ No newline at end of file