Created
November 19, 2020 14:34
-
-
Save felixhummel/4a25be3437f4015f59ed807c110fe3f0 to your computer and use it in GitHub Desktop.
systemd user service
This file contains hidden or 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
# 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