Last active
December 29, 2023 00:17
-
-
Save ivangonzalezg/f4ae48abfd4873d8b980b3cb9a469d4c to your computer and use it in GitHub Desktop.
Create a Deamon on Ubuntu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set up the service to start on server restart | |
sudo systemctl enable ZZZZZZ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create the executable | |
#!/bin/bash | |
# Project folder | |
cd /home/ubuntu/YYYYYY | |
# Command to start the project | |
yarn start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a file in “/etc/systemd/system” and add the extension “.service” | |
[Unit] | |
Description=Node API trigger | |
# Dependent services | |
After=mongod.service | |
[Service] | |
# Username | |
User=root | |
# Executable folder | |
WorkingDirectory=/home/ubuntu | |
# Executable path | |
ExecStart=/home/ubuntu/XXXXXX | |
SuccessExitStatus=143 | |
TimeoutStopSec=10 | |
Restart=on-failure | |
RestartSec=10 | |
[Install] | |
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pro tip: Create a script to update your project | |
#!/bin/bash | |
echo "Stoping ZZZZZZ service" | |
sudo service API stop | |
cd /home/ubuntu/YYYYYY | |
echo "Getting changes" | |
git pull | |
echo "Instaling dependencies" | |
yarn | |
echo "Starting ZZZZZZ service" | |
sudo service ZZZZZZ start | |
echo "ZZZZZZ service updated" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
XXXXXX: name of the executable | |
YYYYYY: folder of the project | |
ZZZZZZ: name of the service |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment