Create a Service

Systemd

Systemd services are defined in unit files with the .service extension. Here's a basic structure:

[Unit]
Description=Your service description
After=network.target

[Service]
Type=simple
User=your_username
WorkingDirectory=/path/to/service/directory
ExecStart=/path/to/service/executable

[Install]
WantedBy=multi-user.target

Replace placeholders: Description: Short description of your service. After: Specify dependencies (e.g., network services). User: User running the service. WorkingDirectory: Service's working directory. ExecStart: Path to the service executable. WantedBy: Target unit to enable automatic startup.

Save the file: Save it as [service_name].service in /etc/systemd/system/.

Reload and enable:

sudo systemctl daemon-reload

Start the service:

SysV

SysV services are typically shell scripts located in /etc/init.d/. Here's a basic example:

Make the script executable:

Start/stop the service:

Optional: Enable automatic startup by linking the script to /etc/rc?.d/S (depending on your runlevel).

Upstart

Upstart uses job files with the .conf extension usually located in /etc/init.

Here's a basic example:

Save the file: Save it as [service_name].conf in /etc/init/.

Reload and start:

Last updated

Was this helpful?