Skip to content

Instantly share code, notes, and snippets.

@stpr-dev
Forked from torch2424/systemDAsUser.service
Created August 30, 2020 18:59
Show Gist options
  • Save stpr-dev/015cac2455c96c81591d064b6a76fd82 to your computer and use it in GitHub Desktop.
Save stpr-dev/015cac2455c96c81591d064b6a76fd82 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment