Skip to content

Ship a templated system systemd unit #1771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nhooyr opened this issue Jun 4, 2020 · 8 comments · Fixed by #1997
Closed

Ship a templated system systemd unit #1771

nhooyr opened this issue Jun 4, 2020 · 8 comments · Fixed by #1997
Milestone

Comments

@nhooyr
Copy link
Contributor

nhooyr commented Jun 4, 2020

Older versions of systemd have problems with the user unit.

See #1747 (comment)

@nhooyr
Copy link
Contributor Author

nhooyr commented Jun 4, 2020

Should also switch from exec service for this file as older systemd's don't recognize it.

For anyone who just wants to use the bundled service now, you can easily fix by running:

sudo cp /usr/lib/systemd/user/code-server.service /etc/systemd/system
sudo sed -i "s/\(Restart=always\)/\1\nUser=$USER/" /etc/systemd/system/code-server.service
sudo systemctl daemon-reload
sudo systemctl enable --now code-server

It'll make code-server a system service and add your current user into the service file and start it for you.

@nhooyr
Copy link
Contributor Author

nhooyr commented Jun 9, 2020

To be clear, the above will fix errors similar to "Failed to get D-Bus connection" which is what happens when using a user unit on an old version of systemd.

@yaerda
Copy link

yaerda commented Jun 9, 2020

@nhooyr Thanks for your solution. After run above cmd, I successed created symlink in default.target, but I can't start code-server, until I change the line 'User=$USER' in code-server.service to 'User=admin' with a real username , and its failed status below:

$systemctl status code-server

● code-server.service - code-server
   Loaded: loaded (/etc/systemd/system/code-server.service; enabled; vendor preset: disabled)
   Active: failed (Result: start-limit) since Tue 2020-06-09 21:25:00 CST; 39min ago
  Process: 8866 ExecStart=/usr/bin/code-server (code=exited, status=217/USER)
 Main PID: 8866 (code=exited, status=217/USER)

Jun 09 21:25:00 instance-1 systemd[1]: code-server.service: main process exited, code=exited, status=217/USER
Jun 09 21:25:00 instance-1 systemd[1]: Unit code-server.service entered failed state.
Jun 09 21:25:00 instance-1 systemd[1]: code-server.service failed.
Jun 09 21:25:00 instance-1 systemd[1]: code-server.service holdoff time over, scheduling restart.
Jun 09 21:25:00 instance-1 systemd[1]: Stopped code-server.
Jun 09 21:25:00 instance-1 systemd[1]: start request repeated too quickly for code-server.service
Jun 09 21:25:00 instance-1 systemd[1]: Failed to start code-server.
Jun 09 21:25:00 instance-1 systemd[1]: Unit code-server.service entered failed state.
Jun 09 21:25:00 instance-1 systemd[1]: code-server.service failed.

So I want to know the cmd

sudo sed -i 's/\(Restart=always\)/\1\nUser=$USER/' /etc/systemd/system/code-server.service

should replace single quote with double quote to add the current real username.

sudo sed -i "s/\(Restart=always\)/\1\nUser=$USER/" /etc/systemd/system/code-server.service

@nhooyr
Copy link
Contributor Author

nhooyr commented Jun 9, 2020

@yaerda Great catch!

@JtMotoX
Copy link

JtMotoX commented Jun 30, 2020

@nhooyr Thank you so much! This works great.

@yaerda And thank you for the input.

You're answer got my instance up and running.

nhooyr added a commit that referenced this issue Jul 22, 2020
systemd's user services are too immature.

See #1771
nhooyr added a commit that referenced this issue Jul 22, 2020
systemd's user services are too immature.

See #1771
nhooyr added a commit that referenced this issue Jul 22, 2020
systemd's user services are too immature.

Closes #1771
@nhooyr
Copy link
Contributor Author

nhooyr commented Jul 22, 2020

Also see the linger issues #1673 #1882 #1861

@nhooyr
Copy link
Contributor Author

nhooyr commented Jul 22, 2020

So the reason I couldn't reproduce before is I use ssh connection sharing which kept my ssh connection open even after I exited. So definitely need this to fix that.

nhooyr added a commit that referenced this issue Jul 22, 2020
systemd's user units are buggy on certain versions
and do not linger by default.

Closes #1771
nhooyr added a commit that referenced this issue Jul 22, 2020
systemd's user units are buggy on certain versions
and do not linger by default.

Closes #1771 #1673 #1882 #1861
nhooyr added a commit that referenced this issue Jul 22, 2020
systemd's user units are buggy on certain versions
and do not linger by default.

Closes #1771 #1673 #1882 #1861
nhooyr added a commit that referenced this issue Jul 22, 2020
systemd's user units are buggy on certain versions
and do not linger by default.

Closes #1771 #1673 #1882 #1861
nhooyr added a commit that referenced this issue Jul 22, 2020
systemd's user units are buggy on certain versions
and do not linger by default.

Closes #1771
Closes #1673
Closes #1882
Closes #1861
nhooyr added a commit that referenced this issue Jul 22, 2020
systemd's user units are buggy on certain versions
and do not linger by default.

Closes #1771
Closes #1673
Closes #1882
Closes #1861
nhooyr added a commit that referenced this issue Jul 22, 2020
systemd's user units are buggy on certain versions
and do not linger by default.

Closes #1771
Closes #1673
Closes #1882
Closes #1861
nhooyr added a commit that referenced this issue Jul 22, 2020
systemd's user units are buggy on certain versions
and do not linger by default.

Closes #1771
Closes #1673
Closes #1882
Closes #1861
nhooyr added a commit that referenced this issue Aug 4, 2020
systemd's user units are buggy on certain versions
and do not linger by default.

Closes #1771
Closes #1673
Closes #1882
Closes #1861
nhooyr added a commit that referenced this issue Aug 25, 2020
systemd's user units are buggy on certain versions
and do not linger by default.

Closes #1771
Closes #1673
Closes #1882
Closes #1861
nhooyr added a commit that referenced this issue Aug 26, 2020
systemd's user units are buggy on certain versions
and do not linger by default.

Closes #1771
Closes #1673
Closes #1882
Closes #1861
nhooyr added a commit that referenced this issue Aug 27, 2020
systemd's user units are buggy on certain versions
and do not linger by default.

Closes #1771
Closes #1673
Closes #1882
Closes #1861
nhooyr added a commit that referenced this issue Aug 27, 2020
systemd's user units are buggy on certain versions
and do not linger by default.

Closes #1771
Closes #1673
Closes #1882
Closes #1861
@nhooyr nhooyr added this to the v3.5.0 milestone Aug 31, 2020
@nhooyr
Copy link
Contributor Author

nhooyr commented Aug 31, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants