Philosophy
Everything in systemd is a unit; Unit files - defined in ini files, located under /etc/systemd/system/*.service - describes units behave.
Unit File
- [Unit] → description + dependencies
- [Type] section (e.g.
[Service]) → how it runs - [Install] → enable/disable wiring, ie defines how a unit is enabled, when
systemctl enable sample.serviceis invoked
Unit Types
service→ start/stop a processsocket→ listen on a socket, start service on demandtimer→ schedule work (cron replacement)mount→ mount filesystemstarget→ grouping + synchronization
Install
WantedBy=→ where this unit is hooked eg systemd’s targetsRequiredBy=→ hard dependencyAlias=→ alternate unit nameAlso=→ enable/disable extra units together
Sample configuration file
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
Environment="JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.362.b09-4.el9.x86_64"
Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"
Environment="CATALINA_HOME=/opt/tomcat"
Environment="CATALINA_BASE=/opt/tomcat"
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
RestartSec=10
Restart=always
[Install]
WantedBy=multi-user.target