0
votes

I am having trouble getting the following startup-script to execute properly when launching a Compute Engine Instance (GCE).

#! /bin/bash
setup vncserver
vnc4server -geometry 1440x900 :1
export DISPLAY=:1
echo "completed"

The script is read by GCE but does not execute the commands and the log shows blank lines with a message in-between which is the key to the problem but I cant seem to solve it.

Log shows the following:

Feb  3 09:15:33 simpleapache3 startupscript: Running startup script /var/run/google.startup.script
Feb  3 09:15:34 simpleapache3 startupscript:
Feb  3 09:15:34 simpleapache3 startupscript: You will require a password to access your desktops.
Feb  3 09:15:34 simpleapache3 startupscript:

How do I get around the "You will require a password..." section?

Tried:

I tried adding in a password inside the script like this but no luck...

#! /bin/bash
#setup vncserver
vnc4server -geometry 1440x900 :1
myPassword123
export DISPLAY=:1
echo "completed"

Notes:

I have got VNC4SERVER already installed on the persistent disk I am adding. If I ssh into the instance and run the commands manually they work perfectly and I am not asked for a password.

Any help would be greatly appreciated...

1

1 Answers

1
votes

I suspect this is because the startup scripts run as root rather than your user.

This script works for me:

#! /bin/bash
echo "I am: " `whoami`
sudo -u briandorsey DISPLAY=:1 vnc4server -geometry 1440x900 :1
echo "completed"

Replace briandorsey with your username.

Also, don't forget to create a firewall rule to allow vnc traffic. This can be done via the Console or with gcutil:

gcutil addfirewall vnc2 --allowed=tcp:5901

This will allow traffic on port 5901 to all virtual machines in your project. See the firewall docs for information on how to limit access further.