Skip to content

Instantly share code, notes, and snippets.

@felixhummel
Created November 19, 2020 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felixhummel/4a25be3437f4015f59ed807c110fe3f0 to your computer and use it in GitHub Desktop.
Save felixhummel/4a25be3437f4015f59ed807c110fe3f0 to your computer and use it in GitHub Desktop.
systemd user service
# first, allow user services to be started on boot
# you only need to do this once
sudo loginctl enable-linger $USER
# this must be set to "no" (the default)
grep KillUserProcesses /etc/systemd/logind.conf
# create your user service file
mkdir -p ~/.config/systemd/user
cat <<EOF > ~/.config/systemd/user/server-8337.service
[Unit]
Description=expose home directory with http
[Service]
WorkingDirectory=%h
ExecStart=/usr/bin/python -m http.server 8337
[Install]
WantedBy=default.target
EOF
# start, check and verify the service
systemctl --user start server-8337.service
systemctl --user status server-8337.service
curl localhost:8337
# enable service to be run on boot
systemctl --user enable server-8337.service
# be sure to log out and try again (from the outside)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment