Skip to content

Commit 221e95e

Browse files
authored
Bundle systemd system unit (#1997)
systemd's user units are buggy on certain versions and do not linger by default. Closes #1771 Closes #1673 Closes #1882 Closes #1861
2 parents 864a9e7 + 255fa37 commit 221e95e

File tree

6 files changed

+24
-9
lines changed

6 files changed

+24
-9
lines changed

ci/build/code-server-user.service

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[Unit]
2+
Description=code-server
3+
After=network.target
4+
5+
[Service]
6+
Type=exec
7+
ExecStart=/usr/bin/code-server
8+
Restart=always
9+
10+
[Install]
11+
WantedBy=default.target

ci/build/code-server.service

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ After=network.target
66
Type=exec
77
ExecStart=/usr/bin/code-server
88
Restart=always
9+
User=%i
910

1011
[Install]
1112
WantedBy=default.target

ci/build/nfpm.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ homepage: "https://github.com/cdr/code-server"
1212
license: "MIT"
1313
files:
1414
./ci/build/code-server-nfpm.sh: /usr/bin/code-server
15-
./ci/build/code-server.service: /usr/lib/systemd/user/code-server.service
15+
./ci/build/code-server.service: /usr/lib/systemd/system/code-server.service
16+
# Only included for backwards compat with previous releases that shipped
17+
# the user service. See #1997
18+
./ci/build/code-server-user.service: /usr/lib/systemd/user/code-server.service
1619
./release-standalone/**/*: "/usr/lib/code-server/"

doc/guide.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ sed -i.bak 's/auth: password/auth: none/' ~/.config/code-server/config.yaml
131131
Restart `code-server` with (assuming you followed the guide):
132132

133133
```bash
134-
systemctl --user restart code-server
134+
sudo systemctl restart code-server@$USER
135135
```
136136

137137
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
277277
Assuming you have been following the guide, restart `code-server` with:
278278

279279
```bash
280-
systemctl --user restart code-server
280+
sudo systemctl restart code-server@$USER
281281
```
282282

283283
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
295295
and then restart `code-server` with:
296296

297297
```bash
298-
systemctl --user restart code-server
298+
sudo systemctl restart code-server@$USER
299299
```
300300

301301
### How do I securely access development web services?

doc/install.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ commands presented in the rest of this document.
8181
```bash
8282
curl -fOL https://github.com/cdr/code-server/releases/download/v3.4.1/code-server_3.4.1_amd64.deb
8383
sudo dpkg -i code-server_3.4.1_amd64.deb
84-
systemctl --user enable --now code-server
84+
sudo systemctl enable --now code-server@$USER
8585
# Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml
8686
```
8787

@@ -90,7 +90,7 @@ systemctl --user enable --now code-server
9090
```bash
9191
curl -fOL https://github.com/cdr/code-server/releases/download/v3.4.1/code-server-3.4.1-amd64.rpm
9292
sudo rpm -i code-server-3.4.1-amd64.rpm
93-
systemctl --user enable --now code-server
93+
sudo systemctl enable --now code-server@$USER
9494
# Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml
9595
```
9696

@@ -99,7 +99,7 @@ systemctl --user enable --now code-server
9999
```bash
100100
# Installs code-server from the AUR using yay.
101101
yay -S code-server
102-
systemctl --user enable --now code-server
102+
sudo systemctl enable --now code-server@$USER
103103
# Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml
104104
```
105105

@@ -108,7 +108,7 @@ systemctl --user enable --now code-server
108108
git clone https://aur.archlinux.org/code-server.git
109109
cd code-server
110110
makepkg -si
111-
systemctl --user enable --now code-server
111+
sudo systemctl enable --now code-server@$USER
112112
# Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml
113113
```
114114

install.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ echo_systemd_postinstall() {
8484
echoh
8585
cath << EOF
8686
To have systemd start code-server now and restart on boot:
87-
systemctl --user enable --now code-server
87+
sudo systemctl enable --now code-server@$USER
8888
Or, if you don't want/need a background service you can run:
8989
code-server
9090
EOF

0 commit comments

Comments
 (0)