HolyGuacamole
Posts: 15
Joined: Sat Dec 20, 2014 10:22 am

starting a VNC server on boot

Sun Apr 05, 2015 8:45 am

Hello forum,

I 've run into a small problem. I'm trying to access the raspberry via a VNC server. This works. :D
I tried to make the server start when the raspberry pi starts up using this tutorial.
That doesn't. :cry:
What could be the problem?
What steps could I take to check if the server is running?

thanks in advance

User avatar
AndyD
Posts: 2333
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: starting a VNC server on boot

Sun Apr 05, 2015 8:53 am

Yes, that tutorial appears to be incorrect. Specifically the init.d script is set up for the user root, which doesn't have a password on a stock Raspbian install. There is a pull request to make changes to the documentation. The change is to make the init.d script as follows:-

Code: Select all

### BEGIN INIT INFO
# Provides: vncboot
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start VNC Server at boot time
# Description: Start VNC Server at boot time.
### END INIT INFO

#! /bin/sh
# /etc/init.d/vncboot

USER=pi
HOME=/home/pi

export USER HOME

case "$1" in
 start)
  echo "Starting VNC Server"
  #Insert your favoured settings for a VNC session
  su - pi -c "/usr/bin/vncserver :0 -geometry 1280x800 -depth 16 -pixelformat rgb565"
  ;;

 stop)
  echo "Stopping VNC Server"
  /usr/bin/vncserver -kill :0
  ;;

 *)
  echo "Usage: /etc/init.d/vncboot {start|stop}"
  exit 1
  ;;
esac

exit 0
I haven't tested this, but it looks like it should work.
Last edited by AndyD on Mon Apr 06, 2015 1:45 pm, edited 1 time in total.

HolyGuacamole
Posts: 15
Joined: Sat Dec 20, 2014 10:22 am

Re: starting a VNC server on boot

Sun Apr 05, 2015 2:23 pm

I changed the file and and did the chmod 755 vncboot again.
after that I did update-rc.d vncboot defaults
That said this.
vncboot2 was an attempt to fix it similar to this one.
What does it mean?

Code: Select all

[email protected] /etc/init.d $ sudo update-rc.d vncboot defaults
update-rc.d: using dependency based boot sequencing
insserv: script vncboot2: service vncboot already provided!
When I restart it I still can't login using the vnc

User avatar
xoopha
Posts: 106
Joined: Mon Feb 09, 2015 9:52 pm

Re: starting a VNC server on boot

Sun Apr 05, 2015 4:55 pm

Do you boot into the console or into the desktop? IIRC VNC server can't run unless there's X running.

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: starting a VNC server on boot

Sun Apr 05, 2015 4:57 pm

xoopha wrote:Do you boot into the console or into the desktop? IIRC VNC server can't run unless there's X running.
What?

Vnc can run if there is no X. Tightvncserver simply starts its own X.
There are 10 types of people: those who understand binary and those who don't.

HolyGuacamole
Posts: 15
Joined: Sat Dec 20, 2014 10:22 am

Re: starting a VNC server on boot

Sun Apr 05, 2015 7:26 pm

xoopha wrote:Do you boot into the console or into the desktop? IIRC VNC server can't run unless there's X running.
I boot into console.

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: starting a VNC server on boot

Sun Apr 05, 2015 7:30 pm

HolyGuacamole wrote:
xoopha wrote:Do you boot into the console or into the desktop? IIRC VNC server can't run unless there's X running.
I boot into console.
A running x is not needed, the problem resides elsewhere.
There are 10 types of people: those who understand binary and those who don't.

DirkS
Posts: 10088
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: starting a VNC server on boot

Sun Apr 05, 2015 7:33 pm

The error message seems to be clear enough: somehow there is already a 'vncboot' service active. Disable and remove that, then install the new service.

User avatar
xoopha
Posts: 106
Joined: Mon Feb 09, 2015 9:52 pm

Re: starting a VNC server on boot

Sun Apr 05, 2015 8:04 pm

kusti8 wrote:
HolyGuacamole wrote:
xoopha wrote:Do you boot into the console or into the desktop? IIRC VNC server can't run unless there's X running.
I boot into console.
A running x is not needed, the problem resides elsewhere.
Oh right, sorry, I was thinking of x11vnc which actually requires an existing desktop session to connect to.

User avatar
AndyD
Posts: 2333
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: starting a VNC server on boot

Sun Apr 05, 2015 10:45 pm

AndyD wrote:I haven't tested this, but it looks like it should work.
I will try testing this myself today.

User avatar
AndyD
Posts: 2333
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: starting a VNC server on boot

Mon Apr 06, 2015 2:51 am

I have run through the process myself (using the init.d script from the pull request as posted above) and it works for me.

HolyGuacamole
Posts: 15
Joined: Sat Dec 20, 2014 10:22 am

Re: starting a VNC server on boot

Mon Apr 06, 2015 10:02 am

DirkS wrote:The error message seems to be clear enough: somehow there is already a 'vncboot' service active. Disable and remove that, then install the new service.
Ok, this is what i tried.
I removed vncboot2 from etc/init.d/
and then reapplied:
chmod 755 vncboot
update-rc.d vncboot defaults

then I rebooted:
sudo reboot

When I attempt to connect to the pi using TightVNC Viewer it says this:
Error in TightVNC Viewer: No connection could be made because the target machine actively refused it.

in the shell when i type:
service --status-all

it lists a lot including:

[ ? ] vncboot

so...

:?

User avatar
AndyD
Posts: 2333
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: starting a VNC server on boot

Mon Apr 06, 2015 11:39 am

Can you tell me what happens if you try the following commands. First

Code: Select all

netstat -l  | grep 590
should produce something like

Code: Select all

tcp        0      0 *:5900                  *:*                     LISTEN
Next

Code: Select all

sudo service vncboot stop
should produce something like

Code: Select all

Stopping VNC Server
Killing Xtightvnc process ID 2432
The ID will be different.

Next

Code: Select all

sudo service vncboot start
should produce something like

Code: Select all

Starting VNC Server

New 'X' desktop is raspberrypi:0

Starting applications specified in /home/pi/.vnc/xstartup
Log file is /home/pi/.vnc/raspberrypi:0.log
Can you post any results that are different than the ones I have shown. Also, make sure that /etc/init.d/vncboot is the one I have posted above, not the one in the Raspberry Pi documentation.

HolyGuacamole
Posts: 15
Joined: Sat Dec 20, 2014 10:22 am

Re: starting a VNC server on boot

Mon Apr 06, 2015 12:37 pm

the first one does not produce anything

the second...
Stopping VNC Server

Can't find file /home/pi/.vnc/raspberrypi:0.pid
You'll have to kill the Xtightvnc process manually

Code: Select all

### BEGIN INIT INFO
# Provides: vncboot
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start VNC Server at boot time
# Description: Start VNC Server at boot time.
### END INIT INFO

#! /bin/sh
# /etc/init.d/vncboot

USER=pi
HOME=/home/pi

export USER HOME

case "$1" in
 start)
  echo "Starting VNC Server"
  #Insert your favoured settings for a VNC session
  su -pi -c "/usr/bin/vncserver :0 -geometry 1280x800 -depth 16 -pixelformat rgb565"
  ;;

 stop)
  echo "Stopping VNC Server"
  /usr/bin/vncserver -kill :0
  ;;

 *)
  echo "Usage: /etc/init.d/vncboot {start|stop}"
  exit 1
  ;;
esac

exit 0
when I copied this from gedit, I noticed that at the bottom it says
Matlab table width: 8

Is this ok?

User avatar
AndyD
Posts: 2333
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: starting a VNC server on boot

Mon Apr 06, 2015 12:40 pm

HolyGuacamole wrote:

Code: Select all

  su -pi -c "/usr/bin/vncserver :0 -geometry 1280x800 -depth 16 -pixelformat rgb565"
There is a missing space between the dash (-) and the pi. It should be:-

Code: Select all

  su - pi -c "/usr/bin/vncserver :0 -geometry 1280x800 -depth 16 -pixelformat rgb565"
Edit the file then try:-

Code: Select all

sudo service vncboot start

HolyGuacamole
Posts: 15
Joined: Sat Dec 20, 2014 10:22 am

Re: starting a VNC server on boot

Mon Apr 06, 2015 12:52 pm

The space was the problem....... a space :cry:
thanks for all the help.
it works now

HolyGuacamole
Posts: 15
Joined: Sat Dec 20, 2014 10:22 am

Re: starting a VNC server on boot

Thu Apr 09, 2015 8:38 am

I decided my mistake should have some educational value. :lol: :lol:
why does the - pi need a space and the -c not?
can the -c have a space? (e.i. - c)

Code: Select all

su - pi -c "/usr/bin/vncserver :0 -geometry 1280x800 -depth 16 -pixelformat rgb565"

User avatar
AndyD
Posts: 2333
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: starting a VNC server on boot

Thu Apr 09, 2015 9:38 am

HolyGuacamole wrote:I decided my mistake should have some educational value. :lol: :lol:
why does the - pi need a space and the -c not?
can the -c have a space? (e.i. - c)

Code: Select all

su - pi -c "/usr/bin/vncserver :0 -geometry 1280x800 -depth 16 -pixelformat rgb565"
Have a look at the manual page for su, use the following in a terminal:-

Code: Select all

man su
The su command takes a number of command line options. In Linux the defacto standard for command line options is to use a dash character for command line options. The dash (-) and (-c) are both command line options to the su command. Additionally the su command be provided with a username on the command line, in our case the user pi. If there is no space between the dash and the pi, the su command will interpret it as a command line option -pi, and will exit with an error.

jimsmith93
Posts: 20
Joined: Mon Mar 23, 2015 5:46 pm

Re: starting a VNC server on boot

Thu Apr 09, 2015 1:16 pm

I could not get the VNC server to successfully start on boot either. Then I tried AndyD's revised script and success!
Thanks :D

User avatar
AndyD
Posts: 2333
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: starting a VNC server on boot

Thu Apr 09, 2015 1:21 pm

jimsmith93 wrote:I could not get the VNC server to successfully start on boot either. Then I tried AndyD's revised script and success!
Thanks :D
Thanks, but I can't take credit for the changes. They are changes waiting to be merged into the Raspberry Pi documentation as suggested by Github user Balsimir

jimsmith93
Posts: 20
Joined: Mon Mar 23, 2015 5:46 pm

Re: starting a VNC server on boot

Sun Apr 12, 2015 3:44 pm

Then...thank you Balsmir too.

User avatar
Alomamabobo
Posts: 1
Joined: Wed Apr 29, 2015 7:41 pm
Location: South France

Re: starting a VNC server on boot

Wed Apr 29, 2015 7:43 pm

Thank You :)

jogl
Posts: 93
Joined: Sun Mar 13, 2016 12:02 pm
Location: SW Ontario Canada

Re: starting a VNC server on boot

Thu Jan 12, 2017 6:48 pm

Sorry about this, I know that this is an old thread.

Where could I find a copy of the tutorial referred to in the OP's post?

Edit: Found it.

http://elinux.org/RPi_VNC_Server

Return to “Troubleshooting”