Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Running code-server as systemd service on Ubuntu #3652

Answered by code-asher
mrducnguyen asked this question in Q&A
Discussion options

Hi,

I'm trying to run code-server as a systemd service on Ubuntu 20.04

Here's my service unit

[Unit]
Description=VSCode on the web
After=nginx.service
[Service]
User=user
Group=user
WorkingDirectory=/home/user/coder
Environment="PATH=/home/user/coder"
ExecStart=/usr/bin/code-server --bind-addr 127.0.0.1:8888
[Install]
WantedBy=multi-user.target

But keep running into this error when I tried to start the service with: systemctl start code-server

systemctl status code-server
くろまる code-server.service - VSCode on the web
 Loaded: loaded (/lib/systemd/system/code-server.service; disabled; vendor preset: enabled)
 Active: failed (Result: exit-code) since Tue 2021年06月22日 12:12:17 AEST; 7s ago
 Process: 525044 ExecStart=/usr/bin/code-server --bind-addr 127.0.0.1:8888 (code=exited, status=127)
 Main PID: 525044 (code=exited, status=127)
systemd[1]: Started VSCode on the web.
code-server[525044]: /usr/bin/env: ‘sh’: No such file or directory
systemd[1]: code-server.service: Main process exited, code=exited, status=127/n/a
systemd[1]: code-server.service: Failed with result 'exit-code'.

If I'm on a console window, logged in as user user, I can run this command /usr/bin/code-server --bind-addr 127.0.0.1:8888 without any issue and code-server is working properly.

here's the user's line in /etc/passwd

user:x:1000:1000:User Name,,,:/home/user:/bin/bash

I'm confused. Not sure where to look at

You must be logged in to vote
This is just a guess but it might not be able to find `sh` since you have overridden `PATH` (which is what is used to find binaries). You might be able to just remove the `Environment` line entirely. Are there binaries in `/home/user/coder` you need to be available? If you do need `/home/user/coder` in the path you could try adding it to your `~/.bashrc` or `~/.profile` instead. Something like: ``` PATH="/home/user/coder:$PATH" ``` If you really need it in the systemd file then you could try running `printenv PATH` and then copy that into your systemd file (since you can't use environment variables in `Environment` so the line above won't work). It might look something like this: ``` Envi...

Replies: 2 comments 2 replies

Comment options

code-server[525044]: /usr/bin/env: ‘sh’: No such file or directory

Hmmm 🤔 Maybe @code-asher or @oxy knows

You must be logged in to vote
0 replies
Comment options

This is just a guess but it might not be able to find `sh` since you have overridden `PATH` (which is what is used to find binaries). You might be able to just remove the `Environment` line entirely. Are there binaries in `/home/user/coder` you need to be available? If you do need `/home/user/coder` in the path you could try adding it to your `~/.bashrc` or `~/.profile` instead. Something like: ``` PATH="/home/user/coder:$PATH" ``` If you really need it in the systemd file then you could try running `printenv PATH` and then copy that into your systemd file (since you can't use environment variables in `Environment` so the line above won't work). It might look something like this: ``` Environment="PATH=/home/user/coder:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin" ```
You must be logged in to vote
2 replies
Comment options

Thanks for your suggestions, I'll try and feedback later. The service unit content was copied from another issue thread in this repo. sh is by default in the system wide PATH environment (/etc/environment), so looks like the ENVIRONMENT=... is not needed at all. :) I'm still quite new with setting up services in Linux.

/home/user/coder is just an empty directory where code-server use as working dir

Comment options

confirm that after removing the Environment=... line from my code-server.service , code-server was able to startup

Answer selected by jsjoeio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /