Setting Up a Systemd Service

Overview

This guide provides the main points for setting up a systemd service with a working directory, an ExecStart command, and automatic restart functionality.

Steps

1. Create a Systemd Service File

2. Define Service Configuration

In the service file, include the following sections:

[Unit]

[Service]

[Install]

3. Enable and Start the Service

4. Monitoring and Maintenance

Example

Here's an example of a systemd service file for a Node.js application:

[Unit] Description=Node.js Example App After=network.target [Service] WorkingDirectory=/path/to/nodejs/app ExecStart=/usr/bin/node /path/to/nodejs/app/app.js User=nodeuser Restart=on-failure RestartSec=10 [Install] WantedBy=multi-user.target