Skip to content

Instantly share code, notes, and snippets.

@torch2424
Last active August 29, 2024 01:41
Show Gist options
  • Save torch2424/a2d4632831db4327b02d839147685007 to your computer and use it in GitHub Desktop.
Save torch2424/a2d4632831db4327b02d839147685007 to your computer and use it in GitHub Desktop.
Run a systemd service as a user
# How to create systemd services: http://neilwebber.com/notes/2016/02/10/making-a-simple-systemd-file-for-raspberry-pi-jessie/
# Digital ocean on a mongodb service: https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-ubuntu-16-04
[Unit]
Description=Run SystemD as users
After=network.target
[Service]
Type=simple
User=[USER HERE]
WorkingDirectory=[USER HOME]
ExecStart=/bin/bash --login -c 'source [USER_HOME]/.bashrc; cd [Directory of command] && [COMMAND TO RUN]'
Restart=always
[Install]
WantedBy=multi-user.target
@EvilSupahFly
Copy link

I realize I'm late to the party here, so I'll keep it brief. I used this template to make a Minecraft Java server run as a systemd service on a Ubuntu Server (no gui). When running minecraft.service as USER=MINECRAFT, I'm still required to authenticate as root when I stop/start/restart the server service (like when Minecraft releases a new version and I have to upgrade the core server .JAR).

Is there a way I can NOT have to authenticate as root, and just allow the service to be started/stopped/restarted as the regular user? Or is this just the nature of the beast when dealing with systemd?

Screenshot from 2023-06-18 11-14-39

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