Skip to content

Instantly share code, notes, and snippets.

@ellisbrown
Created September 6, 2022 23:03
Show Gist options
  • Save ellisbrown/3f7eea6d4d859100bcad601c9135f8c1 to your computer and use it in GitHub Desktop.
Save ellisbrown/3f7eea6d4d859100bcad601c9135f8c1 to your computer and use it in GitHub Desktop.

Revisions

  1. ellisbrown created this gist Sep 6, 2022.
    63 changes: 63 additions & 0 deletions vnc.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,63 @@
    # VNC Server

    ***NOTE:*** I randomly chose display number `:99` for this demo. If you are working on a shared machine, you should choose a random number so that you do not conflict with other users.

    ## Installation
    1. Install TigerVNC:
    ```bash
    sudo apt install tigervnc-standalone-server -y
    ```
    2. Start the VNC server:
    ```bash
    # create a virtual display (#99) for ai2thor to use
    vncserver -localhost no -httpPort 5999 :99
    ```
    This will require you to set a password. The final output should be something like:
    ```text
    New 'MACHINE:99 (USER)' desktop at :99 on machine MACHINE
    ```
    Once the display is created, you AI2thor should have somthing to connect to.
    3. Set the `DISPLAY` environment variable to the corresponding screen number `:99`. The conda environment *should* have this set by default. If not, run the following command to update the conda environment variable:
    ```bash
    conda activate <env_name>
    conda env config vars set DISPLAY=:99
    ```
    - In any python code, you may also need to set the `DISPLAY` environment variable to the corresponding display number to get it to run correctly (e.g. `os.environ['DISPLAY'] = ':99'`).
    4. Fixing issues with the virtual screen
    * See the status by running
    ```bash
    vncserver -list
    ```
    The following is an example of the output with a stale screen:
    ```text
    TigerVNC server sessions:
    X DISPLAY # PROCESS ID
    :99 30309 (stale)
    ```
    * Kill the screen using the following command:
    ```bash
    vncserver -kill :99
    ```
    Now repeat step 2!


    ##### VNC help:
    * You can use `vncserver -kill :99` to kill the server if you want.
    * viewing the display:
    - there are various VNC viewers. I use the built in one on Mac. Instructions below:

    ## Mac VNC Viewer:

    You need to forward the port of the VNC server (`5999` above) to your local machine over SSH, and have a stable connection open. Then you can open the viewer with:
    ```bash
    open vnc://localhost:5999
    ```

    ## Headless VNC Server
    * install dummy XServer
    ```bash
    sudo apt install xterm xserver-xorg-video-dummy
    ```
    * https://www.sproutworkshop.com/2021/04/how-to-create-a-virtual-headless-tigervnc-server-on-ubuntu-20-04/