DEV Community

Cover image for How to setup a service in a SSH Server
Sazardev
Sazardev

Posted on

How to setup a service in a SSH Server

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
Enter fullscreen mode Exit fullscreen mode

/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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Image of Docusign

Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay