Raspberry Pi: Eseguire vncserver all’avvio

Raspberry Pi

Finalmente è arrivato a casa il Raspberry Pi. Settimane di attesa per poter smanettare un pò vicino a questo fantastico “giocattolino”.

Assieme a mio fratello abbiamo cercato di installare subito vncserver, ma le soluzioni che si trovano online : running-vncserver-at-startup , hanno bisogno dell’avvio del server grafico per poter lanciare correttamente il demone di vncserver.

Per ovvirare a questa limitazione, la mia soluzione avvia il demone di vncserver tramite lo script di avvio: /etc/rc.local 

[sourcecode language=”bash”]
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi

#Start Vnc Server
export USER=pi
vncserver :1

exit 0

[/sourcecode]

Prima di lanciare il comando di avvio del server, ho dovuto esportare la variabile globale USER altrimenti il demone non riusciva a leggere correttamente i file di configurazione che avevo editato in /home/pi/.vnc e mi dava il seguente errore:

"Starting vncserver: Starting VNC server: 3: root vncserver: The USER
environments variable is not set"

Al primo avvio vi chiederà di inserire la password di accesso, poi la setterà in automatico ad ogni riavvio.