This is an old revision of the document!
Systemd Service Script
General Information
Creating a systemd until file (service script).
Checklist
- Enterprise Linux 7
Unit File Reference
- /usr/lib/systemd/system ⇒ system unit configuration files (default with system)
- /etc/systemd/system ⇒ additional configuration files (downloaded or custom)
Implementation
- Download the code
- Modify each section to make sense for your service
- Copy to /etc/systemd/system/<name-of-service>.service
- Start your service
systemctl start <name-of-service> ---- ====== The Service Unit File ====== <code bash myprog.service> [Unit] Description=My Awesome Program After=syslog.target [Service] EnvironmentFile=/etc/myprog.d/config ExecStart=/usr/local/bin/myprog.sh Restart=on-abort [Install] WantedBy=multi-user.target
- Description ⇒ Displays near the top of output on “systemctl status myprog.service”
- After ⇒ can be any valid “.target” unit
- 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.
/usr/local/bin/myprog.sh
#!/bin/bash echo "Welcome to my program" logger -p info "$0 has started on $(date)" while true; do logger -p info "$0 is still running..." sleep 30 done