Custom systemd services
Fire script after docker.service is up
[Unit]
Description=scriptName or description
After=docker.service
BindsTo=docker.service
ReloadPropagatedFrom=docker.service
[Service]
Type=oneshot
ExecStart=/usr/local/bin/someSript.sh
ExecReload=/usr/local/bin/someSript.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Java app example
[Unit]
Description=Email service
Requires=network.target remote-fs.target
After=network.target remote-fs.target
[Service]
Type=simple
PIDFile=/path_to_PID/****.pid
User=ubuntu
Group=ubuntu
WorkingDirectory=/opt/apps/
ExecStart=/usr/bin/java -jar /opt/apps/email-1.0.0.jar
StandardOutput=append:/var/log/app.log
StandardError=append:/var/log/app-error.log
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target
commands
- Enable systemd service - it will create soft link
sudo systemctl enable custom.service
- If you changed systemd config you need to reload it.
sudo systemctl daemon-reload
sudo systemctl start custom.service
sudo systemctl stop custom.service
sudo systemctl restart custom.service
sudo systemctl status custom.service