Skip to content

Deploy the code server to a public IP #1928

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
Yegiri opened this issue Jul 30, 2020 · 16 comments
Closed

Deploy the code server to a public IP #1928

Yegiri opened this issue Jul 30, 2020 · 16 comments

Comments

@Yegiri
Copy link

Yegiri commented Jul 30, 2020

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?

@Yegiri Yegiri added the feature label Jul 30, 2020
@code-asher
Copy link
Member

There's no collaboration yet. We'll update #33 when that changes.

code-server has a heartbeat file that tells you whether it's in use (~/.local/share/code-server/heartbeat, see #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.

@Yegiri
Copy link
Author

Yegiri commented Jul 30, 2020

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?

@code-asher
Copy link
Member

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.

@Yegiri
Copy link
Author

Yegiri commented Jul 30, 2020

I got it.
Thanks a lot!

@Yegiri Yegiri closed this as completed Jul 30, 2020
@Yegiri Yegiri reopened this Jul 30, 2020
@Yegiri
Copy link
Author

Yegiri commented Jul 30, 2020

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.

@code-asher
Copy link
Member

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.

@Yegiri
Copy link
Author

Yegiri commented Jul 31, 2020

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?

@code-asher
Copy link
Member

code-asher commented Jul 31, 2020

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.

@Yegiri Yegiri closed this as completed Aug 2, 2020
@antofthy
Copy link

antofthy commented Sep 3, 2020

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.

@code-asher
Copy link
Member

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?

@antofthy
Copy link

antofthy commented Sep 3, 2020

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)

@bpmct
Copy link
Member

bpmct commented Sep 8, 2020

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?

@antofthy
Copy link

antofthy commented Sep 17, 2020 via email

@davids-tips
Copy link

davids-tips commented Apr 6, 2021

As of the issue of not being able to access it from the internet without having to use ssh try setting up ngrok
Hope this works for you,

David A. Powell
Beginner in Javascript
Compentent in Python and Discord.py
Proficient in html and css.
OC of WhiskeyBot
See my latest projects at https://Github.com/Davids-tips
Founder of Whiskey Dev Group

@antofthy
Copy link

antofthy commented Apr 6, 2021

As a FYI we are currently working on a web interface, our users sign into that will then let them control their development environment (EG: start, stop, or select a different software setup). This connects to a backend system that has the docker access, to actually do the requested tasks for the user.

@antofthy
Copy link

antofthy commented Dec 20, 2021

Update... a summery of the new web control panel, authenticated used (in this case me) can use to select a docker environment, start it, copy the password, and jump to the code-server login screen.

#792 (comment)

The next step would be to somehow do away with the need to copy the password to code server, either though a link argument, or retrieving and setting the users 'session token cookie' seeing as we have already authenticated them.

The next step would be to somehow do away with the need to copy the password to code server, either though a link argument, or retrieving and setting the users 'session token cookie' seeing as we have already authenticated them.

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

No branches or pull requests

5 participants