I'm trying to start an X application automatically when the system enters run level 5.
What is the correct way to do this?
I've written a script and put it in /etc/init.d/
I've run the appropriate chkconfig commands to setup up the symbolic links in the /etc/rcX.d directories.
Everything works fine except the script can't start the X application when I run:
/sbin/service scriptName start
Error: Can't open display:
Error: Can't open display: :0
Rather than defining an init script, you should be having X (or your window manager) start the process automatically. X, KDE, and Gnome all have ways of automatically starting things up (i.e. ~/.kde4/Autostart).
If this IS just X, go modify your /etc/X11/xinit/xinitrc file (or equivalent) to have it run your command. Mine looks like this at the bottom of the file:
if [ -n "$failsafe" ]; then twm & xclock -geometry 50x50-1+1 & xterm -geometry 80x50+494+51 & xterm -geometry 80x20+494-0 & exec xterm -geometry 80x66+0+0 -name login else exec $command fi
So you would change that to run whatever command you want.