Talk:RPi VNC Server

From eLinux.org
Revision as of 01:12, 15 April 2013 by Saamac1 (talk | contribs) (typo fix.)
Jump to: navigation, search

Just a note to say that although this set-up worked beautifully, it meant that I was always VNC'ing in as root. By using su, I could run as any user, e.g.:

### BEGIN INIT INFO
# Provides:             vncserver
# 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

export USER=root
export HOME=/root
export RUN_USER=pi

case "$1" in
  start)
    echo "Starting VNC Server"
    su - $RUN_USER -c "/usr/bin/vncserver :1 -geometry 1280x1024 -depth 24"
    ;;

  stop)
    echo "Stopping VNC Server"
    su - $RUN_USER -c "/usr/bin/vncserver -kill :1"
    ;;

  *)
    echo "Usage: $0 {start|stop}"
    exit 1
    ;;
esac

exit 0

init scripts should be merged into one

Hi. I think the init scripts on this page should be merged into one, since both of them have some problems and you probably want to run a VNC server as your unprivileged user anyway.

In the first script, you can't simply do this:

USER=root
HOME=/root

export USER HOME

This page explains why you can't do that.

Overall, the script should look something like this:

### BEGIN INIT INFO
# Provides: tightvnc
# 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 the Tight VNC Server at boot time.
### END INIT INFO

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

USER='pi' # Change your desired user here

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

 stop)
   pkill Xtightvnc
   echo "Tight VNC server stopped"
   ;;

 restart)
   pkill Xtightvnc
   #Insert your favoured settings for a VNC session
   su $USER -c '/usr/bin/vncserver :0 -geometry 1280x800 -depth 16 -pixelformat rgb565'
   echo "Tight VNC server restarted"
   ;;

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

exit 0

It's based on both of the scripts on the page, as well as my own experience with init scripts. I've also added a restart option, for well, easy restarting of the server.

Tom Slominski

Link to working script

Both scripts on this wikipage have problems, but I found this discussion where you can find working script: http://www.raspberrypi.org/phpBB3/viewtopic.php?p=108862