Last active
August 29, 2024 01:41
-
-
Save torch2424/a2d4632831db4327b02d839147685007 to your computer and use it in GitHub Desktop.
Run a systemd service as a user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Thanks, needed to see how to run a service as a user and this worked when other suggestions didn't ✅
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?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PR: this fork contains a number of simplifications.