This content originally appeared on DEV Community and was authored by Sazardev
You get a connection with ssh, and then you run your project or a command. You are innocent and just close the terminal assuming that your command will run forever in the SSH Server. If this was your case (Or you're just curios) let me help you to do a real Service in Linux for your SSH Server.
First of all we need to go to /etc
in your SSH Server. So, if you are already logged in just put in the terminal:
cd /etc
/etc
is where we have our system configuration files, it's like our nerve center of our system, so be careful of what you are touching here please. Also, that is why we are putting a service file right here. Let's dive into:
cd system/system
And here is where we create a new file called: [name of your service].service
, in my case will be named deploy-frontend.service
. So, in the terminal you will need to add:
vim deploy-frontend.service
And now we have a new file service! That is great but not all. Let me explain to you the syntax of the new file.
[Unit]
# Here we describe our service
Description=Serve run for frontend
[Service]
# Here we are going to detail the actions of our service
ExecStart={path_of_the_command} -s /home/dev/app/dist -l 5000
Restart=always
User={your_username}
[Install]
# And here we define what users had this service
And in my case my service looks like this:
[Unit]
Description=Serve run for frontend
[Service]
ExecStart=/usr/bin/serve -s /home/dev/app/dist -l 5000
Restart=always
User=dev
[Install]
WantedBy=multi-user.target
This content originally appeared on DEV Community and was authored by Sazardev
Sazardev | Sciencx (2024-07-18T19:56:16+00:00) How to setup a service in a SSH Server. Retrieved from https://www.scien.cx/2024/07/18/how-to-setup-a-service-in-a-ssh-server/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.