I've been struggling with this long enough to ask yet another startup script question.
I've got a startup script that is relatively simple, ie:
### BEGIN INIT INFO
# Provides: startVNC
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Start VNC server at boot time
# Description: Test
### END INIT INFO
#!/bin/sh
echo "JOB RUN AT $(date)"
echo "============================"
echo ""
/usr/bin/vncserver -geometry 1280x1024 -depth 24
Obviously it's only the last line that's really important. The script is executable, ie.
ls -l startVNC
yields:
-rwxr-xr-x 1 root root 406 2011-12-07 15:45 startVNC
When I execute it when logged in over ssh as my_user
vncserver starts and I am able to see the GUI from my desktop. So then I tried 5 things to make it run on start-up:
- Copying my script to
/etc/init.d/
, callingupdate-rc.d -f startVNC defaults
(also with99
afterdefaults
to make sure everythingvncserver
depended on is already running). I checked all the generated symbolic links were there in the/etc/rcX.d/
folders. But it didn't work on reboot or start-up - Adding my script to
/etc/rc.local
beforeexit 0
- Adding to
crontab -e
as@reboot /home/my_user/scripts/startVNC
- Adding my script to
/etc/init.d/rcS
- Adding my script to System -> Preferences -> Startup Applications in Gnome
but none of them worked. What more can I check. Is there an error in my script maybe? I guess the process'es owner has to be my_user
for it to work, but I have no idea how to debug it.
Any clues appreciated.
Best Answer
You could use
su
[YourUserName]-c /usr/bin/vncserver
to run the vncserver as user, not as root.Another point: In your script, there's no difference between starting and stopping the VNC server. Usually, a init script would use different cases to start/stop the service:
Here's an elaborated example how to start a vnc server using an init script.