- What is a Systemd service file?
- A Systemd service file (.service) is a configuration file that defines and manages background processes (daemons) on Linux systems. It specifies how a service should start, when it should restart, and what dependencies it has.
- Which service type should I choose?
- It depends on your application behavior. Most standard applications use 'simple'. Traditional daemons that fork and run in background use 'forking'. Scripts that run once use 'oneshot'. Modern applications that can signal readiness use 'notify'.
- Where should I place the service file?
- Place custom service files in /etc/systemd/system/. Package manager-installed services go in /usr/lib/systemd/system/. Files in /etc/systemd/system/ always take precedence.
- How do I make a service restart automatically when it fails?
- Set 'Restart=on-failure' in the Service section. This will automatically restart the service when it exits with a non-zero exit code or terminates abnormally. You can add 'RestartSec=5' to wait 5 seconds before restarting.
- What should I do after changing a service file?
- After modifying a service file, you must run 'systemctl daemon-reload' to make systemd aware of the changes. Then run 'systemctl restart servicename' to restart the service with the new configuration.