Monday, October 17, 2016

VNC Viewer

I recently built a desktop for development in my company’s CORP network. By using VNC, I can access the same Gnome session even from home. Just simply connect to VPN, and start a vnc viewer, I can resume what I do at office.
I have a CentOS 6 on my development desktop. I installed RPM pacakages: vnc-server. (TODO: Details about setting up VNC server.)
I tried TigerVNC Viewer, but it was really bad, especially F8 menu key because I use Eclipse, F8 is used a lot when you are debugging. And there is not a pop-up menu bar like VirtualBox when you are in full-screen mode.
RealVNC satisfies all my requirements about VNC:
  • A menu bar
  • Better configuration UI on Windows 7
  • I can write a script to start VNC viewer
    through SSH tunnel make the viewer goes into full-screen mode on my secondary display automatically.
In CORP network, just click the VNC button on Windows’ taskbard, type the password, the viewer is in full-screen mode on my secondary display.
#!/bin/bash
set -e

shutdown() {
  if [ -n "$tunnel_pid" ]; then
    kill $tunnel_pid
  fi
}

trap shutdown EXIT

ssh -N -L 5902:localhost:5902 mydev.desktop &
tunnel_pid=$!

~/apps/bin/VNC-Viewer-5.2.1-Windows-64bit.exe \
  --Monitor='\\.\Display2' \
  --FullScreen=1 \
  localhost:2
I also installed cygwin on Windows so that I could use OpenSSH. The script can clean up the SSH tunnel once the script quits.
At home, the network connection is slow. And that script will fail because RealVNC gets timeout. I didn’t find how to make RealVNC wait for a longer time. I just simply run SSH tunnel and viewer separately in different screens of GNU Screen in a Cygwin terminal.
I chose JPEG encode for better performance when I at home.
Here is the script using SSH Control Socket to stop the tunnel. %h is a TOKEN of SSH, which will be substituted with the host name SSH tries to access. Check ControlPath of ssh-config.
#!/bin/bash
set -e

SSH_HOST=bwang.desktop.mycompany.com
CTL_SOCK=/tmp/ssh_tunnel_%h.sock

shutdown() {
    ssh -S $CTL_SOCK -O stop $SSH_HOST
}

trap shutdown EXIT

ssh -f -N -L 5902:localhost:5902 -M -S $CTL_SOCK -o ExitOnForwardFailure=yes $SSH_HOST

if [ $? -eq 0 ]; then
    /Applications/RealVNC/VNC\ Viewer.app/Contents/MacOS/vncviewer \
          -useaddressbook    $SSH_HOST
else
    echo "Failed to start SSH tunnel!"
fi

Sunday, October 9, 2016

Don't set limit nofile to unlimited

After I set nofile to unlimited in /etc/security/limits.d/90-nproc.conf like this,
*          hard    nproc     unlimited
*          hard    nofile    unlimited

*          soft    nproc     unlimited
*          soft    nofile    unlimited
I could not boot into Gnome on my VM running CentOS 6.8 any more. Even I could switch to a terminal using ctrl-alt-F2, I seemed not be able to log in. I reboot the VM using a live-cd ISO. Then mount the file system, after setting to 32K as below, reboot it, the problem was fixed.
*          -    nproc     unlimited
*          -    nofile    32768
Notes:
# find out the logical volume of the hard drive
fdisk -l

# mount the logical volume
mkdir /mnt/hd
mount /dev/mapper/Volume-lv_root /mnt/hd
vi /mnt/hd/etc/security/limits.d/90-nproc.conf