I have a PC which runs Lubuntu 14.10 without a monitor. The user is autologged in. I have created a Sysvinit script and installed it on /etc/init.d. My script amongst other things, starts a jar file that opens a GUI application that listens on serial port.

The problem is that I can't make the jar application start automatically on boot. Java complains that it cannot connect to the X11 display server. However this is the strange thing. If I ssh into the machine and run the script myself with sudo service it starts normally. Also if I have a monitor connected during boot, it also starts correctly by itself.

How can I get the script started without a monitor connected? It seems as if when a monitor is not connected, Xorg server isn't initiated.

  • Possible duplicate of askubuntu.com/questions/26610/… – Luke Feb 24 '15 at 21:26
  • The question is, why do you need a GUI without a monitor (or I got some part wrong)? – Luke Feb 24 '15 at 21:26
  • @Luke thanks for your answer. The GUI is a required part of the application monitoring and processing data from the serial port. It's a third party application needed to produce the results so not my choice! :-) Any idea about the problem? – mitsos1os Feb 24 '15 at 21:30
  • Have you tried following that answer? Use pastebin.com/y8tRZpJa as xorg.conf (edit drivers and other details accordingly), run Xorg -configure if needed and add nomodeset in /etc/default/grub. Or fake a monitor by plugging in resistors :D I can't try any of that atm, but I think it's worth a shot – Luke Feb 24 '15 at 21:40
  • I can see that many people have the problem of X server not starting without a monitor attached. But how come everything works correctly if I ssh and issue the command manually without a monitor? Does ssh force in some way X server to load? – mitsos1os Feb 24 '15 at 21:47

You can have any application run with a virtual X frame buffer using tools like Xvfb or Xvnc. You should also consider switching to using a language that doesn't force you to have a running X to connect to.

That things work if you use ssh to connect to the machine is not a surprise. Try making the connection after first entering unset DISPLAY, or by doing

ssh -o "ForwardX11 no" owl
  • So Ssh DOES start a X11 Session? If so, isn't there a way to manually trigger what is called by ssh login without installing xvfb? I will try the solution and post results. Thanks – mitsos1os Feb 25 '15 at 6:13
  • @mitsos1os No it doesn't start one, it forwards the one that is already running on your workstation to the server via a separate channel (separate from you typing command etc). "ForwardX11 no" prohibits that (and may make your connection connect somewhat faster). X was designed from the start to run over a network. – Anthon Feb 25 '15 at 6:47
  • I actually did try to connect with ssh -o "ForwardX11 no" user@host and still the jar ran! How is this happening? – mitsos1os Feb 25 '15 at 7:41
  • @mitsos1os Please don't provide information one bit at a time. Of course your unset DISPLAY as suggested well, did you have the same result? Other result? What happens if you start firefox or some other X based application with and without that? – Anthon Feb 25 '15 at 8:10
  • I am sorry you misunderstood me, I tried -o ForwardX11 no after you suggested it to see if it actually won't work but it did.... Here is also another clue. I tried removing the script from autostart and also I connected a keyboard on the pc. After I wait till it boots, I blindly type CTRL+ALT+T to open a terminal, and type the command to run the script. And guess what! It also works! The script is run. So it has to be something else. I also tried switching to the root account with su and running it also works. It only seems to bother it when it is autostarted – mitsos1os Feb 25 '15 at 8:29

After a lot of troubleshooting and help from @Anthon Anthon, I finally managed to achieve what I wanted. The problem after all was that X server did not have enough time to load. The Xserver was started from lightdm that was an upstart service, and my script started from init.d.

It seems that if a monitor is connected X server starts earlier and my script in init.d didn't crash.

A simple sleep 10 command to stall the execution of the script until X server started did the trick. However this is a guess of time when X server will start. So a more elegant solution would be to check when the desktop starts and then launch my app. In order to achieve this I inserted the following lines before launching my script.

while [ -z $(pidof lxsession) ]; do
   echo "LXSession not started yet, waiting for 2 secs"
   sleep 2

with -z $(pidof lxsession) I check if the returned string of pidof is null. (So No PID found for process lxsession). As soon as lxsession starts, the loop is canceled and the script moves on to the execution of my java app that now finds the X server and runs normally.

Thank you all for your help. I hope other people are helped by this thread and not tortured like me!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.