Code-server: Working directory not opened on launch

Created on 27 Sep 2019  ·  14Comments  ·  Source: cdr/code-server


  • code-server version: 2.1523-vsc1.38.1
  • OS Version: Debian 9.11, Google Cloud Platform

Description

The working directory is not loaded when opening the browser, worked on previous versions of code-server. No directory is loaded at all. I have to open it manually.

code-server.service (running as part of systemctl)

[Unit]
Description=VS Code Server
After=network.target
AssertPathExists=/home/steve/go/src/github.com/companyorg/repo

[Service]
Type=simple
Environment=GOPATH=/home/steve/go
Environment=PATH=/home/steve/.go/bin:/home/steve/bin:/usr/local/bin:/usr/bin:/bin:/home/steve/go/bin
Environment=GOROOT=/home/steve/.go
WorkingDirectory=/home/steve/go/src/github.com/companyorg/repo
ExecStart=/usr/bin/code-server --allow-http --no-auth --port=8443
User=steve
Restart=always
RestartSec=1

[Install]
WantedBy=multi-user.target

Steps to Reproduce

  1. Create a service under /etc/systemd/system/code-server.service by placing the above config in a file
  2. sudo systemctl enable code-server.service
  3. sudo systemctl start code-server.service
  4. Open a browser and go to the code server at 8443. No directory is opened.
question

Most helpful comment

OMG..... slap me

remove these two lines

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

not sure where I got those and it seems to work fine

so the working file for anyone that googles this a year from now->

[Unit]
Description=Code Server IDE
After=network.target

[Service]
Type=simple
User=student1
WorkingDirectory=/home/student1
Restart=on-failure
RestartSec=10
Environment="PASSWORD=blahblahblah"

ExecStart=/opt/code-server /home/student1 --cert
ExecStop=/bin/kill -s QUIT $MAINPID


[Install]
WantedBy=multi-user.target

All 14 comments

You're using v1 flags, and you're not passing $PWD to ExecStart, please refer to our examples in doc/

I have the same problem, using -v $PWD:/home/coder/project or --project-directory $PWD:/home/coder/project doesn't work either.

Here is my docker-compose:

version: '3.7'

services:

    codeserver:
        image: codercom/code-server:v2
        container_name: codeserver
        restart: always
        environment:
         - PUID=1000
         - PGID=1000
         - TZ=Europe/Stockholm
         - PASSWORD=123
        ports:
          - 127.0.0.1:8080:8080
        volumes:
           - coder:/home/coder
        command: --auth password
volumes:
    coder:
        driver: local-persist
        driver_opts:
            mountpoint: /home/aron/code/coder

Cheers! And thank you for doing this, I love it 🥇

I have the same problem, using -v $PWD:/home/coder/project or --project-directory $PWD:/home/coder/project doesn't work either.

Here is my docker-compose:

version: '3.7'

services:

    codeserver:
        image: codercom/code-server:v2
        container_name: codeserver
        restart: always
        environment:
         - PUID=1000
         - PGID=1000
         - TZ=Europe/Stockholm
         - PASSWORD=123
        ports:
          - 127.0.0.1:8080:8080
        volumes:
           - coder:/home/coder
        command: --auth password
volumes:
    coder:
        driver: local-persist
        driver_opts:
            mountpoint: /home/aron/code/coder

Cheers! And thank you for doing this, I love it 🥇

Please use $(pwd) for now. It's something to deal with how the command parser not handling environment variables properly.

You're using v1 flags, and you're not passing $PWD to ExecStart, please refer to our examples in doc/

I am passing $(pwd) to ExecStart as such:
ExecStart=/usr/bin/code-server $(pwd) --allow-http --no-auth --port=8443

Why doesn't it work? Am I missing something here?
I have also tried manually launching code-server with the start directory as an argument.

Not sure what happened but I cannot reproduce your issue in Debian 10 in GCP.

Instead of $(pwd) just give it . as an argument. That was my solution.
You may also want to ensure the HOME environment variable is set correctly.

If this is still a problem, please feel free to reopen.

You're using v1 flags, and you're not passing $PWD to ExecStart, please refer to our examples in doc/

did the documentation remove the systemd method?

Yes, those docs became frequently out of date and weren't maintained well. Writing a systemd unit is out of scope anyhow, code-server doesn't require anything special.

Maybe it's best if we have a single guide on running code-server on a VM in GCP with systemd. Would be much easier to maintain. Before we tried to have guides for every platform under the sun.

I have this working in RHEL 7.7

[student1@ansible ~]$ cat /etc/systemd/system/code-server.service
[Unit]
Description=Code Server IDE
After=network.target

[Service]
Type=simple
User=student1
WorkingDirectory=/home/student1
Restart=on-failure
RestartSec=10
Environment="PASSWORD=ansible1234"

ExecStart=/opt/code-server --cert $(pwd)
ExecStop=/bin/kill -s QUIT $MAINPID
StandardOutput=file:/var/log/code-server-output.log
StandardError=file:/var/log/code-server-error.log

[Install]
WantedBy=multi-user.target

but this fails to work on RHEL8.... nothing in journalctl....

this is so strange to me....

this works->

[student1@ansible ~]$ /opt/code-server --cert

this works->

[student1@ansible ~]$ /opt/code-server --cert $pwd

this does not work

[student1@ansible ~]$ /opt/code-server --cert $(pwd)

this does not work

[student1@ansible ~]$ /opt/code-server --cert /home/student1

this is where I get stuck... the example was very similar to this...

I think that argument will get interpreted as the value to --cert.

Could try code-server --cert -- /home/student1. $pwd is probably not defined which is why it works the same as --cert alone.

I don't think that works either :(. That was my original guess->

[student1@ansible ~]$ sudo vi /etc/systemd/system/code-server.service

here is the systemd file

[student1@ansible ~]$ cat /etc/systemd/system/code-server.service
[Unit]
Description=Code Server IDE
After=network.target

[Service]
Type=simple
User=student1
WorkingDirectory=/home/student1
Restart=on-failure
RestartSec=10
Environment="PASSWORD=ansible1234"

ExecStart=/opt/code-server /home/student1 --cert
ExecStop=/bin/kill -s QUIT $MAINPID
StandardOutput=file:/var/log/code-server-output.log
StandardError=file:/var/log/code-server-error.log

[Install]
WantedBy=multi-user.target

but no dice

[student1@ansible ~]$ sudo systemctl daemon-reload
[student1@ansible ~]$ sudo systemctl restart code-server.service
[student1@ansible ~]$ sudo systemctl status code-server.service
● code-server.service - Code Server IDE
   Loaded: loaded (/etc/systemd/system/code-server.service; enabled; vendor preset: disabled)
   Active: activating (auto-restart) (Result: exit-code) since Tue 2020-03-31 23:11:24 UTC; 4s ago
  Process: 18742 ExecStart=/opt/code-server /home/student1 --cert (code=exited, status=209/STDOUT)
 Main PID: 18742 (code=exited, status=209/STDOUT)

Mar 31 23:11:24 ansible systemd[1]: code-server.service: Main process exited, code=exited, status=209/STDOUT
Mar 31 23:11:24 ansible systemd[1]: code-server.service: Failed with result 'exit-code'.
[student1@ansible ~]$

however.... that one does seem to work on the command line->

[student1@ansible ~]$ /opt/code-server /home/student1 --cert
info  Server listening on https://localhost:8080
info    - Password is 85438d951f9d1ae9f80a7e2e
info      - To use your own password, set the PASSWORD environment variable
info      - To disable use `--auth none`
info    - Using generated certificate and key for HTTPS

OMG..... slap me

remove these two lines

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

not sure where I got those and it seems to work fine

so the working file for anyone that googles this a year from now->

[Unit]
Description=Code Server IDE
After=network.target

[Service]
Type=simple
User=student1
WorkingDirectory=/home/student1
Restart=on-failure
RestartSec=10
Environment="PASSWORD=blahblahblah"

ExecStart=/opt/code-server /home/student1 --cert
ExecStop=/bin/kill -s QUIT $MAINPID


[Install]
WantedBy=multi-user.target
Was this page helpful?
0 / 5 - 0 ratings

Related issues

KSXGitHub picture KSXGitHub  ·  3Comments

grant picture grant  ·  3Comments

avelino picture avelino  ·  3Comments

justmao945 picture justmao945  ·  3Comments

infogulch picture infogulch  ·  3Comments