knute
Posts: 550
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Questions about starting and stopping VNC on boot

Thu Oct 23, 2014 12:39 am

I've installed tightvncserver and it all works just fine. I found this page, http://www.raspberrypi.org/documentatio ... ccess/vnc/, with good instructions on how to start the VNC server on boot. The script from the page however started it as root. I'm not a Linux expert by any stretch but I thought it would be better to start it as pi. I modified the script (see below) changing the USER and HOME variables and using sudo -u pi to start the server.

I've got three questions;
1) In the script below do the USER and HOME variables actually do anything?

2) Is there a problem using sudo in an init script?

3) When I open a terminal window after starting VNC as pi, the working directory is /, I thought it would be /home/pi?

Thanks,

knute...

### 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=root
#HOME=/root
USER=pi
HOME=/home/pi

export USER HOME

case "$1" in
start)
echo "Starting VNC Server"
#Insert your favoured settings for a VNC session
#/usr/bin/vncserver :0 -geometry 1920x1080 -depth 24
sudo -u pi /usr/bin/vncserver :0 -geometry 1920x1080 -depth 24
;;

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

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

exit 0

Return to “Raspberry Pi OS”