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

Image

Chris LaPointe

Another site of Code

Back to Overview