Manage Systemd Service
Create & Manage Systemd Service
Create a systemd service
|
|
Add the following content to the service file (.service)
|
|
Cheatsheet
| Name | Description | Value |
|---|---|---|
| Description | Description of the service | |
| After | The service will be started after the network is up | |
| Type | The type of service | simple, forking |
| TimeoutStartSec | The time to wait before starting the service | |
| User | The user to run the service | |
| Group | The group to run the service | |
| WorkingDirectory | The working directory of the service | Eg. The source code directory. |
| ExecStart | The command to start the service | |
| Restart | Restart the service if it crashes | |
| RestartSec | The time to wait before restarting the service | |
| WantedBy | The target to start the service |
Eg. A sample service file for a Golang app
|
|
Enable the service
|
|
Start the service
|
|
Stop the service
|
|
Restart the service
|
|
Check the service status
|
|
Delete the service
|
|
Troubleshooting
Check the service logs
|
|
Retain the logs for a specific time
|
|
Retain the logs for a specific size
|
|
Cheatsheet
| Name | Description |
|---|---|
| journalctl | The command to check the logs |
| -u | The service name |
| -f | Follow the logs |
| -n | The number of logs to show |
| -o | The output format |
| -p | The priority of the logs |
| –vacuum-time | The time to keep the logs |
| –vacuum-size | The size to keep the logs |