Skip to content

Add description for using code-server as a systemd unit #379

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
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions doc/self-hosted/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,30 @@ OPTIONS
```
*Important:* For more details about Apache reverse proxy configuration checkout the [documentation](https://httpd.apache.org/docs/current/mod/mod_proxy.html) - especially the [Securing your Server](https://httpd.apache.org/docs/current/mod/mod_proxy.html#access) section

### Start code-server as systemd unit
Create `/lib/systemd/system/code-server.service` with the following contents:
```
[Unit]
Description=Code Server IDE
After=network.target

[Service]
Type=simple
User=<USER>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also set environment file. There is a instance the User environment is not being used by systemd.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please suggest changes as I am not aware of the issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
User=<USER>
User=<USER>
EnvironmentFile=$HOME/.profile

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, see my systemd Unit file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sr229 The Environment file can't work it has wrong formart systemd expects a other formart it will not execute that file with if else statements.

VAR=VALUE

is the only thing that is accepted in it!

EnvironmentFile=$HOME/.profile
Restart=on-failure
RestartSec=10

ExecStart=<PATH TO BINARY> --allow-http

StandardOutput=file:/var/log/code-server-output.log

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Ubuntu 16.04 the Standard* options were not recognized. I ended up with the following systemd unit (I anyways prefer logging to go to journald):

[Unit]
Description=VSCode in a browser
After=network.target

[Service]
Type=simple
User=myuser
EnvironmentFile=$HOME/.profile
Restart=on-failure
RestartSec=10

ExecStart=/usr/local/bin/code-server --allow-http --port 1234 --no-auth --disable-telemetry $HOME/dev-workspace

ExecStop=/sbin/start-stop-daemon --stop -x /usr/local/bin/code-server

[Install]
WantedBy=multi-user.target

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a more viable alternative is to log this to journald if needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should always be logging to journald.

StandardError=file:/var/log/code-server-error.log

[Install]
WantedBy=multi-user.target

```
Enable code-server with `systemctl enable code-server.service`. Start with `systemctl start code-server.service`.

### Help
Use `code-server -h` or `code-server --help` to view the usage for the cli. This is also shown at the beginning of this section.