Article Image
read

Simple systemd service

There aren't very many simple examples on the internet of simple systemd services, so I thought I might share one of my examples.

This is a simple service that runs as part of ubsub. I've changed some of the details to masque what the service is (though you could probably guess).

The service is a simple non-forking service, that will auto-restart on failure, and will only boot after the network target is ready.

The file exists in: /etc/systemd/system/myservice.service

[Unit]
Description=UbSub Service
After=network.target

[Service]
WorkingDirectory=/path/to/service
Environment=env1=val1
Type=simple
User=root
ExecStart=/bin/bash -c "exec npm run start:cluster"
Restart=on-failure

[Install]
WantedBy=multi-user.target

Running

If you changed the .service file, make sure to run systemctl daemon-reload

To start your service: systemctl start myservice To stop your service: systemctl stop myservice

And to enable your service (start at boot): systemctl enable myservice

Blog Logo

Christopher LaPointe


Published

Interested in Related Posts from this Site?

Persistent Terminal in VSCode Remote Session

September 19, 2020: I've been moving around a bit lately (Nowhere far... since COVID-19 and all), and have...

Backing up with B2 and Restic

April 01, 2019: # Backing up with Blazeback B2 and Restic For a long while I had managed...

Weak Delegates 2

February 08, 2016: Weak Delegates 2 After toying with weak delegates a bit more, I found that although...

Weak Delegates

January 10, 2016: Weak Delegates in CSharp Problem This idea has always plagued me -- how do I...

Events and Expressions

March 13, 2015: Events and Expressions I ran into a scenario recently where I had a C# Action...

Image

Chris LaPointe

Another site of Code

Back to Overview