3

This is the tightvncserver init.d script, tightvncserver, in /etc/init.d:

============
### BEGIN INIT INFO
# Provides:     tightvncserver
# Required-Start:   $remote_fs $syslog
# Required-Stop:    $remote_fs $syslog
# Default-Start:    2 3 4 5
# Default-Stop:     0 1 6
# Short-Description:    tightvncserver starts at boot time
# Description:      Start tightvncserver connection service
### END INIT INFO

#
# set the USER variable for the VNC server
#
# Note: Starting the VNC Server on :1 means we need to connect to port 5901
#
# To install:
#
# sudo chown root:root /etc/init.d/tightvncserver
# sudo chmod 755 /etc/init.d/tightvncserver
# sudo update-rc.d tightvncserver defaults
#
#
export USER=pi
export HOME=/home/pi

eval cd ~$USER

case "$1" in
start)
    su - $USER -c "/usr/bin/tightvncserver -geometry 1280x720 -depth 24 :1"
    echo "Starting TightVNC server for $USER"
    ;;

stop)
    pkill Xtightvnc
    echo "TightVNC server stopped"
    ;;

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

Here is the ls -l:

-rwxr-xr-x 1 root root 918 Dec 13 14:02 tightvncserver

It will run when I type at the command prompt:

sudo ./tightvncserver start

But it does not run at boot time. I have done the command:

sudo update-rc.d tightvncserver defaults

Can anyone explain what is wrong?

Jacobm001
  • 11,797
  • 7
  • 45
  • 56
Ric Steinberger
  • 33
  • 1
  • 2
  • 5

2 Answers2

6

If you are running Jessie this should be started with a systemd service. I copied from https://www.raspberrypi.org/forums/viewtopic.php?t=123457&p=830506

Create a new file /etc/systemd/system/vncserver@.service with the following contents:

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=forking
User=pi
PAMName=login
PIDFile=/home/pi/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%i
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

Make executable

sudo chmod +x  /etc/systemd/system/vncserver@.service

You can test with

sudo systemctl start vncserver@1.service

Enable with

sudo systemctl daemon-reload && sudo systemctl enable vncserver@1.service
Milliways
  • 54,718
  • 26
  • 92
  • 182
  • This seemed to work, though it sure looks like magic when compared to the simpler (IMHO) "start | stop" approach to scripting. Thanks very much! – Ric Steinberger Dec 13 '15 at 22:44
  • When i try to test above method with the `start` command. I get following error `Job for vncserver@1.service failed. See 'systemctl status vncserver@1.service' and 'journalctl -xn' for details.`. [Here's gist of those command's errors.](https://gist.github.com/girishsortur/59d10afbd1e1057234c5). Thanks – giri-sh Dec 27 '15 at 07:00
3

I used crontab instead, which worked fine for me.

 sudo crontab -e

Select editor for yourself i used nano editor which i felt easy myself.

@reboot su - pi -c '/usr/bin/tightvncserver :1'

or if you use VNC server instead of tightvncserver.

@reboot su - pi -c '/usr/bin/vncserver :1'

Explanation of the command: "su" is a user to select, "pi" is a name of user; you may have other users, "c" defines as command followed by in single quotations.

TIPS:

My suggestions is that before you reboot your pi please run the rebootcode

su - pi -c '/usr/bin/vncserver :1'

So this will verify us if there is a display available for that particular user, if not it will ask you to submit password for your display. Just give some password and remember that will be your VNC viewer password. And then reboot your pi. Open your vncviewer/tightvncviewer from your computer type "IP-RASPBERRYpi:1" then password. If everything goes well you can now access your pi in GUI with VNCVIEWER. Cheers..

  • After hours of (newb) searching, this solution worked without any other weird errors or mucking through arcane settings. I used `@reboot su - pi -c '/usr/bin/vncserver :1 -geometry 1600x900 -depth 24'` to make the display a little bigger. – apathos May 05 '17 at 23:41