Skip to content

Instantly share code, notes, and snippets.

@amitkhare
Last active August 12, 2023 12:27
Show Gist options
  • Save amitkhare/fc68c4fac3550a4908c807888ddef5d8 to your computer and use it in GitHub Desktop.
Save amitkhare/fc68c4fac3550a4908c807888ddef5d8 to your computer and use it in GitHub Desktop.
Systemd Service as USER start at Boot
[Unit]
Description=Service Description
After=network.target
[Service]
Type=simple
ExecStartPre=/bin/sleep <TIME-IN-SECONDS>
User=<USER>
Group=<GROUP>
Restart=always
# Compose up
ExecStart=/usr/bin/podman-compose -f /opt/npm/docker-compose.yml up
# Compose down, remove containers and volumes
ExecStop=/usr/bin/podman-compose -f /opt/npm/docker-compose.yml down -v
[Install]
WantedBy=default.target
@amitkhare
Copy link
Author

amitkhare commented Jul 22, 2023

Above script should help start a user service at system boot

##Make Sure service has WantedBy=default.target otherwise it wont start at the boot

This service located at :

$ /etc/systemd/system/myuser.service

Reload Systemctl Deamon

$ sudo systemctl daemon-reload

Enable login linger for that user:

$ sudo loginctl enable-linger <USER>

Start the Service

$ sudo systemctl start myapp.service

Enable the Service

$ sudo systemctl enable myapp.service

Reboot and wait for a while to start the service, then check; Should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment