From 255fa37e1d058cce917eb75c2da20c2c806a52c2 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Wed, 22 Jul 2020 15:58:51 -0400 Subject: [PATCH] Bundle systemd system unit systemd's user units are buggy on certain versions and do not linger by default. Closes #1771 Closes #1673 Closes #1882 Closes #1861 --- ci/build/code-server-user.service | 11 +++++++++++ ci/build/code-server.service | 1 + ci/build/nfpm.yaml | 5 ++++- doc/guide.md | 6 +++--- doc/install.md | 8 ++++---- install.sh | 2 +- 6 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 ci/build/code-server-user.service diff --git a/ci/build/code-server-user.service b/ci/build/code-server-user.service new file mode 100644 index 000000000..a2f48e938 --- /dev/null +++ b/ci/build/code-server-user.service @@ -0,0 +1,11 @@ +[Unit] +Description=code-server +After=network.target + +[Service] +Type=exec +ExecStart=/usr/bin/code-server +Restart=always + +[Install] +WantedBy=default.target diff --git a/ci/build/code-server.service b/ci/build/code-server.service index a2f48e938..bfb62d78d 100644 --- a/ci/build/code-server.service +++ b/ci/build/code-server.service @@ -6,6 +6,7 @@ After=network.target Type=exec ExecStart=/usr/bin/code-server Restart=always +User=%i [Install] WantedBy=default.target diff --git a/ci/build/nfpm.yaml b/ci/build/nfpm.yaml index ed8e1ea6d..38bffe859 100644 --- a/ci/build/nfpm.yaml +++ b/ci/build/nfpm.yaml @@ -12,5 +12,8 @@ homepage: "https://github.com/cdr/code-server" license: "MIT" files: ./ci/build/code-server-nfpm.sh: /usr/bin/code-server - ./ci/build/code-server.service: /usr/lib/systemd/user/code-server.service + ./ci/build/code-server.service: /usr/lib/systemd/system/code-server.service + # Only included for backwards compat with previous releases that shipped + # the user service. See #1997 + ./ci/build/code-server-user.service: /usr/lib/systemd/user/code-server.service ./release-standalone/**/*: "/usr/lib/code-server/" diff --git a/doc/guide.md b/doc/guide.md index 11a8781c8..8782f57f8 100644 --- a/doc/guide.md +++ b/doc/guide.md @@ -131,7 +131,7 @@ sed -i.bak 's/auth: password/auth: none/' ~/.config/code-server/config.yaml Restart `code-server` with (assuming you followed the guide): ```bash -systemctl --user restart code-server +sudo systemctl restart code-server@$USER ``` Now forward local port 8080 to `127.0.0.1:8080` on the remote instance by running the following command on your local machine. @@ -277,7 +277,7 @@ sudo setcap cap_net_bind_service=+ep /usr/lib/code-server/lib/node Assuming you have been following the guide, restart `code-server` with: ```bash -systemctl --user restart code-server +sudo systemctl restart code-server@$USER ``` Edit your instance and checkmark the allow HTTPS traffic option. @@ -295,7 +295,7 @@ Edit the `password` field in the `code-server` config file at `~/.config/code-se and then restart `code-server` with: ```bash -systemctl --user restart code-server +sudo systemctl restart code-server@$USER ``` ### How do I securely access development web services? diff --git a/doc/install.md b/doc/install.md index c4e1f82a9..26df03b16 100644 --- a/doc/install.md +++ b/doc/install.md @@ -81,7 +81,7 @@ commands presented in the rest of this document. ```bash curl -fOL https://github.com/cdr/code-server/releases/download/v3.4.1/code-server_3.4.1_amd64.deb sudo dpkg -i code-server_3.4.1_amd64.deb -systemctl --user enable --now code-server +sudo systemctl enable --now code-server@$USER # Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml ``` @@ -90,7 +90,7 @@ systemctl --user enable --now code-server ```bash curl -fOL https://github.com/cdr/code-server/releases/download/v3.4.1/code-server-3.4.1-amd64.rpm sudo rpm -i code-server-3.4.1-amd64.rpm -systemctl --user enable --now code-server +sudo systemctl enable --now code-server@$USER # Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml ``` @@ -99,7 +99,7 @@ systemctl --user enable --now code-server ```bash # Installs code-server from the AUR using yay. yay -S code-server -systemctl --user enable --now code-server +sudo systemctl enable --now code-server@$USER # Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml ``` @@ -108,7 +108,7 @@ systemctl --user enable --now code-server git clone https://aur.archlinux.org/code-server.git cd code-server makepkg -si -systemctl --user enable --now code-server +sudo systemctl enable --now code-server@$USER # Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml ``` diff --git a/install.sh b/install.sh index 1038adc7d..36c81aa0a 100755 --- a/install.sh +++ b/install.sh @@ -84,7 +84,7 @@ echo_systemd_postinstall() { echoh cath << EOF To have systemd start code-server now and restart on boot: - systemctl --user enable --now code-server + sudo systemctl enable --now code-server@$USER Or, if you don't want/need a background service you can run: code-server EOF