Enable persistent user systemd services
loginctl enable-linger $user
Create a user systemd directory
mkdir -p ~/.config/systemd/user
Create a systemd configuration
touch my-service.service
Example service
[Unit]
Description=myservice
After=network.target
[Service]
EnvironmentFile=/home/user/.myservice_env
Restart=always
RestartSec=5
ExecStart=/usr/bin/java -jar /home/user/my-service.jar
[Install]
WantedBy=multi-user.target
# WantedBy=default.target *use this if you want to start on boot*
For more info and details of options checkout this
Reload the user daemon (this must be done on every change to your service file)
systemctl --user daemon-reload
Starting and or stop your service as needed
systemctl --user [start|stop|restart] my-service
Also see this systemd github issue for debugging help