Code-server: Deploy the code server to a public IP

Created on 30 Jul 2020  Â·  13Comments  Â·  Source: cdr/code-server


If I deploy the code server to a public IP, then everyone can use it.
So how do I know if someone is using it or not?

And I want to know whether code-server supports multiple collaborative coding now?

feature

All 13 comments

There's no collaboration yet. We'll update https://github.com/cdr/code-server/issues/33 when that changes.

code-server has a heartbeat file that tells you whether it's in use (~/.local/share/code-server/heartbeat, see https://github.com/cdr/code-server/issues/1274 for more details). There isn't a way to distinguish multiple users though. You'd need to use some kind of external authentication for that.

I found the file heartbeat in both the local device and the code-server, so which one should I believe or they are same?
And I log into the code-server, but both files are blank, why?

Use the one that's on the same machine code-server is running on. You might have a local one if you ran code-server locally once, maybe?

The heartbeat file doesn't have any content, we just update the modified timestamp. We update it every minute so if the timestamp is more than a minute ago it means code-server is currently inactive.

I got it.
Thanks a lot!

Sorry, I still have a little question.
I am running code-server locally, but the timestamp of local file heartbeat is 2020/07/28.
I have run several versions of code-server locally, but I only found one heartbeat.
So, I'm confused now. I don't know how to find the heartbeat of running one.

image
The heartbeat in code-server has also not been updated.

I tried out the latest Docker image but mine seems to be updating. Here's what I got:

coder@154599748d18:~/.local/share/code-server$ stat heartbeat 
  File: heartbeat
  Size: 0               Blocks: 1          IO Block: 131072 regular empty file
Device: 36h/54d Inode: 4051932     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/   coder)   Gid: ( 1000/   coder)
Access: 2020-07-30 22:31:39.303522361 +0000
Modify: 2020-07-30 22:32:39.298647226 +0000
Change: 2020-07-30 22:32:39.298647226 +0000
 Birth: -
coder@154599748d18:~/.local/share/code-server$ stat heartbeat 
  File: heartbeat
  Size: 0               Blocks: 1          IO Block: 131072 regular empty file
Device: 36h/54d Inode: 4051932     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/   coder)   Gid: ( 1000/   coder)
Access: 2020-07-30 22:31:39.303522361 +0000
Modify: 2020-07-30 22:33:39.301773539 +0000
Change: 2020-07-30 22:33:39.301773539 +0000
 Birth: -

The modification time was 22:32 then a minute later it was 22:33.

Are you using a custom data directory with --user-data-dir? And are you running code-server as root? code-server uses the data directory for the heartbeat so maybe it's in a different directory if that flag is set or if it's running under a different user.

No matter how I set the parameter --user-data-dir and user, I can only find one heartbeat on my local device. And it was not modified.
A good news, the heartbeat in code-server is modified. But this file is not modified per-minute. Maybe it has something to do with heartbeat logic?

root@981367a7387c:~/.local/share/code-server# stat heartbeat 
  File: heartbeat
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 71h/113d        Inode: 663435      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2020-07-31 02:58:21.007959000 +0000
Modify: 2020-07-31 03:11:25.025640000 +0000
Change: 2020-07-31 03:11:25.025640000 +0000
 Birth: -
root@981367a7387c:~/.local/share/code-server# stat heartbeat 
  File: heartbeat
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 71h/113d        Inode: 663435      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2020-07-31 02:58:21.007959000 +0000
Modify: 2020-07-31 03:13:23.410951000 +0000
Change: 2020-07-31 03:13:23.410951000 +0000
 Birth: -

At last, I want to know in which time zone is this timestamp?

Hmm, we use a one-minute timer but it might be possible for that to be delayed depending on external factors. It might be safest to check if the heartbeat file was modified in the last five minutes or so. One thing you could test is running code-server with --log trace. That will cause code-server to output "heartbeat" every time it tries to write to the heartbeat file. It should output every minute as long as there is an active connection.

We don't actually specifically set the date; we just write a blank file. So it should just be using the system's timezone. You can find that out with timedatectl or date.

I would add that until you actually connect after starting code-server the heartbeat will not be updating.
While it updates once a minute or so, you should only terminate (or whatever) code-server when it has not updated for some time.

On our systems we use a php-apache contained with code-server running in it (for student web development environments, so each student gets their own independent web server!) and terminate containers only after being idle for more than an hour or so (cron job external to docker container). Only the master node of our docker swarm needs to do this, looking at the users 'home' data, no matter how many nodes are in our swarm.

We also have a command (some script that does idle check actually) that reports idleness of current users..
Example output from script...

Name        Idle  Image        Node 
s2836331 55 secs  web-dev      elf  
s2845086 51 secs  web-dev      elf  
s2875623   53:17  web-dev      elf  
s2884991   40:38  web-dev      elf  
s2894337   56:13  web-dev      elf1 
s2896564 27 secs  web-dev      elf1 
s2911385 21 secs  web-dev      elf 

from that I can see three users are 'idle' and will have the container shutdown shortly.

Thanks for sharing, that's a cool setup.

I would add that until you actually connect after starting code-server the heartbeat will not be updating.

Ahhhh right that explains a lot. Would it be advantageous to touch that file once on startup?

It would make no difference to code-server if you touched it or not. As part of our idle check we also check another file that gets updated when a user issues a remote control for the docker container (to start, or check what their docker environments password is). That way the idle check knows the docker was only just started (and not idle), even if it had not been logged into via web browser, (leaving heartbeat as it was from last session)

I would add that until you actually connect after starting code-server the heartbeat will not be updating.
While it updates once a minute or so, you should only terminate (or whatever) code-server when it has not updated for some time.

On our systems we use a php-apache contained with code-server running in it (for student web development environments, so each student gets their own independent web server!) and terminate containers only after being idle for more than an hour or so (cron job external to docker container). Only the master node of our docker swarm needs to do this, looking at the users 'home' data, no matter how many nodes are in our swarm.

We also have a command (some script that does idle check actually) that reports idleness of current users..
Example output from script...

Name        Idle  Image        Node 
s2836331 55 secs  web-dev      elf  
s2845086 51 secs  web-dev      elf  
s2875623   53:17  web-dev      elf  
s2884991   40:38  web-dev      elf  
s2894337   56:13  web-dev      elf1 
s2896564 27 secs  web-dev      elf1 
s2911385 21 secs  web-dev      elf 

from that I can see three users are 'idle' and will have the container shutdown shortly.

This is pretty awesome! Would you have any interest in doing a blog post, video, or tutorial about this?

Not at this time

On Wed, Sep 9, 2020 at 4:24 AM Ben Potter notifications@github.com wrote:

I would add that until you actually connect after starting code-server the
heartbeat will not be updating.
While it updates once a minute or so, you should only terminate (or
whatever) code-server when it has not updated for some time.

On our systems we use a php-apache contained with code-server running in
it (for student web development environments, so each student gets their
own independent web server!) and terminate containers only after being idle
for more than an hour or so (cron job external to docker container). Only
the master node of our docker swarm needs to do this, looking at the users
'home' data, no matter how many nodes are in our swarm.

We also have a command (some script that does idle check actually) that
reports idleness of current users..
Example output from script...

Name Idle Image Node
s2836331 55 secs web-dev elf
s2845086 51 secs web-dev elf
s2875623 53:17 web-dev elf
s2884991 40:38 web-dev elf
s2894337 56:13 web-dev elf1
s2896564 27 secs web-dev elf1
s2911385 21 secs web-dev elf

from that I can see three users are 'idle' and will have the container
shutdown shortly.

This is pretty awesome! Would you have any interest in doing a blog post /
tutorial about this?

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/cdr/code-server/issues/1928#issuecomment-689054848,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAJIRQCRLGWYHTF6LNRKAOTSEZZEZANCNFSM4PMUDTSA
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

grant picture grant  Â·  3Comments

RealSlimMahdi picture RealSlimMahdi  Â·  3Comments

nol166 picture nol166  Â·  3Comments

justmao945 picture justmao945  Â·  3Comments

rcarmo picture rcarmo  Â·  3Comments