Differences
This shows you the differences between two versions of the page.
linux_wiki:systemd_service_script [2016/01/31 00:47] billdozor [Implementation] |
linux_wiki:systemd_service_script [2019/05/25 23:50] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Systemd Service Script ====== | ||
- | **General Information** | ||
- | |||
- | Creating a systemd until file (service script). | ||
- | |||
- | **Checklist** | ||
- | * Enterprise Linux 7 | ||
- | |||
- | ---- | ||
- | |||
- | ====== Unit File Reference ====== | ||
- | |||
- | * / | ||
- | * / | ||
- | |||
- | ---- | ||
- | |||
- | ====== Implementation ====== | ||
- | |||
- | * Download the code | ||
- | * Modify each section to make sense for your service | ||
- | * Copy to / | ||
- | * Start your service< | ||
- | |||
- | ---- | ||
- | |||
- | ====== The Service Unit File ====== | ||
- | |||
- | <code bash myprog.service> | ||
- | [Unit] | ||
- | Description=My Awesome Program | ||
- | After=syslog.target | ||
- | |||
- | [Service] | ||
- | EnvironmentFile=/ | ||
- | ExecStart=/ | ||
- | Restart=on-abort | ||
- | |||
- | [Install] | ||
- | WantedBy=multi-user.target | ||
- | </ | ||
- | * Description => Displays near the top of output on " | ||
- | * After => can be any valid " | ||
- | * See all: systemctl -t target --all | ||
- | * EnvironmentFile => Configuration file to load | ||
- | * ExecStart => Executable to start | ||
- | * Restart => Auto restarts the program if an un-handled exit error occurs | ||
- | * WantedBy => If enabled, start under which target | ||
- | |||
- | ===== Example: Test Script ===== | ||
- | |||
- | This is the script that was used to test the custom systemd service unit file. | ||
- | |||
- | / | ||
- | <code bash> | ||
- | #!/bin/bash | ||
- | |||
- | echo " | ||
- | logger -p info "$0 has started on $(date)" | ||
- | |||
- | while true; do | ||
- | logger -p info "$0 is still running..." | ||
- | sleep 30 | ||
- | done | ||
- | </ |