1

Starting tightvncserver manually from a terminal works fine. To start it @reboot I am using crontab -e with the following command:

@reboot sleep 20 && /usr/bin/tightvncserver

The path is correct, I tested it using which tightvncserver, but it does not work. I am new to cron, so I do not have experience. What comes to my mind, that there is trouble with the users. Cron does not know, which user should execute this command.

Any help is appreciated!

cerv21
  • 113
  • 1
  • 4
  • See https://raspberrypi.stackexchange.com/a/39374/8697 - while this mentions Jessie it works with Stretch (or any systemd OS). – Milliways Jan 20 '18 at 23:12
  • @Milliways: Thank you very much for your link. This line in cron "at"reboot sudo -u pi /usr/bin/tightvncserver" works for me, but I am not really happy with it. Tightvncserver is an executable which is able to work without sudo. However, "at"reboot -u pi /usr/bin/tightvncserver or "at"reboot pi /usr/bin/tightvncserver, "at"reboot /usr/bin/tightvncserver do not work. – cerv21 Jan 21 '18 at 15:11
  • @Milliways: Edit: su is what I want. I only knew that su is used for root, but I was not familiar with its options. – cerv21 Jan 21 '18 at 15:14

2 Answers2

2

This is how I get it done with cron:

sudo crontab -e

add the line

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

This works flawlessly and doesn't come up with the "no pid" error.

ulr
  • 21
  • 3
0

You can start tightvncserver at startup by adding the line into /etc/rc.local.

rc.local starts after all the services are up after the OS start.

Here is rc.local from Raspberry pi documentation.

Chetan Bhargava
  • 1,262
  • 3
  • 15
  • 29
  • Thank you, but I would like to use cron. I something goes wrong, I have to replace @reboot with some interval of time, such that cron seems to be the better option for me. – cerv21 Jan 21 '18 at 15:06
  • @opens rc.local is your best option but if you want to use some other option, it will be your choice. As you have already mentioned you have tried to use cron but it did not function for you. – Chetan Bhargava Jan 22 '18 at 02:03