wally
Posts: 54
Joined: Mon Aug 06, 2012 12:07 pm

Graphical Application without desktop environment

Mon May 06, 2013 9:24 am

Hello,

i want to start a gambas3 graphical application immediately after boot
without starting the desktop environment.
Is this possible and how to do it ?

thx wally

User avatar
DaveDriesen
Posts: 113
Joined: Sun Mar 31, 2013 8:28 pm
Location: Top of the food chain

Re: Graphical Application without desktop environment

Mon May 06, 2013 4:37 pm

Hi,

There's several ways to go about this, and the best solution depends on your desires or vision.

Have a look at this simplified 3-step method, for auto-booting into anything you want (mediaplayer, game emulator, ...)

- add startx to rc.local using a specific user
- allow that user to start an X session
- configure the user's X init script to launch the app

Step 1: add startx to /etc/rc.local
The easiest cheat to start an application after the linux boot process, is to modify /etc/rc.local. This file is executed as the last step in the init process and you can use it to put all kinds of geeky stuff in there. If you're looking for something more advanced then you can create a script and add it to /etc/init.d, but let's keep things simple. The rc.local file is more than enough for day-to-day needs.

Of course, we'll be wanting to launch the X server. Hence we'll add the startx command to /etc/rc.local.

Code: Select all

#/etc/rc.local
su -s /bin/bash -c startx your_user&
As a step-by-step clarification, this will:
- impersonate a user of your choice (here it is your_user)
- start a shell of your choice (here it is /bin/bash)
- and launch startx within that shell

Step 2: allow non-interactive processes to launch an X server
Your linux distro is likely to come configured so that only root or interactive sessions (consoles or shells) can launch the X server. Non-interactive processes, such as the boot process, are typically prohibited from doing so. Seeing as you want everything to launch automatically at boot, you will need a way around this, or your X session will refuse to start at boot and all you'll see is a bunch of "permission denied" messages on your console instead.

In raspbian, reconfiguring xorg so that any user can launch xorg is done as follows:

Code: Select all

dpkg-reconfigure x11-common
X11-common.png
X11-common.png (17.23 KiB) Viewed 111425 times
Alternatively, edit /etc/X11/Xwrapper.config and change allowed_users=console to allowed_users=anybody.

Step 3: add your application to ~/.xinitrc
Last but not least, you need to add an entry for your gambas3 application to the specified user's xinitrc so that this applications gets started when x comes up:

Code: Select all

#~your_user/.xinitrc
/usr/bin/gambas3
Note that this setup will launch one X session at boot time, and launch your application only once within that session. When the application exits, so will X, and you will be returned to the console. But you get the idea.

If you do need your x session or app to respawn then you'll be better off editing inittab, changing default runlevel, or whatnot.

I have tried to describe a very basic way of having X launch automatically during system startup, and having an application launch within that X session.

Let us know how this works out for you -- thanks!

Dave Driesen
Linux dev and oldskool elite.

bullwinkle
Posts: 118
Joined: Wed Jan 09, 2013 12:14 pm

Re: Graphical Application without desktop environment

Wed Jul 24, 2013 5:29 am

worked for me.....
....many thanks

eng.sergiosoares
Posts: 4
Joined: Wed Jun 26, 2013 7:44 pm

Re: Graphical Application without desktop environment

Mon Oct 07, 2013 8:22 pm

Awesome!

This worked for me with a JAVA Swing application on Raspberry PI.
On step 3, I had to change the permissions to my file ~/.xinitrc by using: sudo chmod 755 ~/.xinitrc

Thank you very much,

Sergio Soares (Brazil)

User avatar
cjnslm
Posts: 4
Joined: Thu Jan 16, 2014 11:33 am

Re: Graphical Application without desktop environment

Thu Jan 16, 2014 11:42 am

Works like a charm in Ubuntu 13.04 with java swing application. Thanks :) !

I do have an extra question:
Can i add to the same x session a remote desktop app such as tightvnc? The idea behind it was to have remote control capabilities for the purpose of technical support to the application.

Thanks in advance to anyone that can help.

User avatar
AndyD
Posts: 2342
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia

Re: Graphical Application without desktop environment

Thu Jan 16, 2014 9:32 pm

cjnslm wrote: Can i add to the same x session a remote desktop app such as tightvnc?
Yes, have a look at x11vnc.

User avatar
cjnslm
Posts: 4
Joined: Thu Jan 16, 2014 11:33 am

Re: Graphical Application without desktop environment

Fri Jan 17, 2014 10:33 am

Thanks for the quick response Andy.
I'm checking out x11vnc but it seems it needs a specific display to attach to and the method described in this post does not initialize any display (checked it with root@localhost> w).
I'm doing further digging for a solution on how to attach vnc server to the x display on which i'm running my java app and if i find a solution i'll be sure to post it back to this thread.
Any help is welcome though :).

User avatar
cjnslm
Posts: 4
Joined: Thu Jan 16, 2014 11:33 am

Re: Graphical Application without desktop environment

Fri Jan 17, 2014 1:03 pm

It seems that whenever i start the application with startx the default display setting is ignored. If i do call startx without .xinitrc, a xterm is initialized and a display is set (as can be seen w output bellow)

Code: Select all

 13:02:39 up 43 min,  4 users,  load average: 0,06, 0,10, 0,13
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     tty2                      12:59    2:47   0.54s  0.00s xinit /etc/X11/xinit/xinitrc -- /etc/X11/xinit/xserverrc :0
pos      tty1                      12:53    8:39   0.79s  0.24s -bash
root     pts/0    192.168.1.73     12:24    7.00s  0.69s  0.01s w
root     pts/1    :0               12:59   23.00s  0.35s  0.30s -su
Help? :P

User avatar
cjnslm
Posts: 4
Joined: Thu Jan 16, 2014 11:33 am

Re: Graphical Application without desktop environment

Fri Jan 17, 2014 3:20 pm

Finally got it :) .
The problem was that the application was being ran by a normal user and i was trying to "attach" a vnc software to that session with the user root.
Once i tried to call x11vnc as the user that runs the java application i got vnc access with no problem.
Hope this helps anyone that has to find a solution to a problem similar to mine.

Thanks for the help Andy, x11vnc is great!

Greener
Posts: 1
Joined: Sat Dec 27, 2014 3:18 am
Location: Bogotá, Colombia

Re: Graphical Application without desktop environment

Sat Dec 27, 2014 3:22 am

Image
I get this always, i'm trying to run PureData Extended, but no results
What does it mean?

Thanks

ghans
Posts: 7893
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Graphical Application without desktop environment

Sat Dec 27, 2014 10:53 am

Use approach 3 posted by Dave Driesen above.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

GlasgowGrin
Posts: 4
Joined: Sun Mar 15, 2015 12:19 pm

Re: Graphical Application without desktop environment

Mon Mar 16, 2015 1:57 pm

I don't understand what i need to do in step 3? :/ can someone clarify please?

One more thing, i run my app like this: sudo java -jar AppName.jar
will it work this way?

User avatar
topguy
Posts: 7313
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Graphical Application without desktop environment

Mon Mar 16, 2015 2:34 pm

If you can run that from shell without entering password it will probably also run from script.
So if you are "pi" user, then according to the description above you do "nano ~/.xinitrc" and enter your command in that file.

I would recommend that this is done in a system that does not automatically start the desktop. Then you can test that it works with "startx" before enabling "boot to desktop".

GlasgowGrin
Posts: 4
Joined: Sun Mar 15, 2015 12:19 pm

Re: Graphical Application without desktop environment

Mon Mar 16, 2015 3:03 pm

oh, i got it to work, thank you for reply :) i was confused with that xinitrc file
now one more question, how do i kill the app that started and get back to gui/console?

User avatar
topguy
Posts: 7313
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Graphical Application without desktop environment

Mon Mar 16, 2015 3:24 pm

Click on the "close" button ?
Choose "file->quit" in the menu ?
Press escape ?

Its your Java application, how should we know ;-)

GlasgowGrin
Posts: 4
Joined: Sun Mar 15, 2015 12:19 pm

Re: Graphical Application without desktop environment

Mon Mar 16, 2015 3:31 pm

it's just a dummy window but lets not get off topic, ill get it somehow :) tyvm anyway

mflach
Posts: 1
Joined: Wed Feb 10, 2016 7:25 pm

Re: Graphical Application without desktop environment

Wed Feb 10, 2016 7:31 pm

I can get my graphical application to launch but I don't have a mouse cursor. I'm using a Logitech wireless keyboard that has an integrated track-pad. The mouse input (button press) works and the UI changes when I move the mouse around but I don't see the mouse cursor.

I've tried a simple gtk application and a xwWidgets application and get the same result.

Any thoughts?

zoomz
Posts: 3
Joined: Mon Apr 25, 2016 5:39 am

Re: Graphical Application without desktop environment

Thu Jul 14, 2016 10:12 am

mflach wrote:I can get my graphical application to launch but I don't have a mouse cursor.
I have the same problem. I run a python script on a raspberry pi raspbian jessie distribution. The window is displayed but with no mouse cursor and no title. Can you help?
Thanks

cashchew
Posts: 2
Joined: Fri Nov 18, 2016 9:06 pm

Re: Graphical Application without desktop environment

Fri Nov 18, 2016 9:14 pm

Hi Dave, I tried your approach to run a python script that uses pyQT5 extensively. Every time I reboot, the GUI application runs at tty2 instead of tty1, and I have to manually switch over to tty2 to see it. Any idea what causes it? Thanks in advance!

Eknem
Posts: 1
Joined: Sat Dec 17, 2016 10:33 pm

Re: Graphical Application without desktop environment

Sat Dec 17, 2016 10:40 pm

Dave,

Can you explain the & sign in
su -s /bin/bash -c startx your_user&

User avatar
topguy
Posts: 7313
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Graphical Application without desktop environment

Mon Dec 19, 2016 10:19 am

The & sign means that the command will be spanwed of in the background so the script continues.

Rooock
Posts: 5
Joined: Thu Mar 16, 2017 1:33 pm
Location: Colombia

Re: Graphical Application without desktop environment

Wed Mar 29, 2017 4:47 pm

HI, i`m looking for a solution to run mi JAVA program at startup and I was very glad to find this thread with all the good comments.
i´m doing the procedure as described but at the moment to execute

Code: Select all

dpkg-reconfigure x11-common
i got an error :o :
update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults
how could be fixed?
hope you could help me guys :?:

Rooock
Posts: 5
Joined: Thu Mar 16, 2017 1:33 pm
Location: Colombia

Re: Graphical Application without desktop environment

Wed Mar 29, 2017 9:38 pm

Sadly I could not open the GUI with the instructions on this post, so at the end I wanted to autostart my java GUI with raspbian after googled a lot and watch on youtube several videos, I took the procedure on this post :
viewtopic.php?f=91&t=65607,
During the thread several guys give enough info to get the autostart gui attached to a lxterminal. For now it just worked for me. 8-)

simondid
Posts: 17
Joined: Tue Nov 17, 2015 7:55 pm

Re: Graphical Application without desktop environment

Fri May 05, 2017 3:44 pm

after a few houres of research and debugging i found a way to make daves process working

the problem seems to be that x server has been updated in some from that disables some of the commands and reinstalling a legacy version of it seems to fix this

the problem is that in step 2 you will and an error when running this command

Code: Select all

dpkg-reconfigure x11-common
saying

Code: Select all

update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults
to fix this there a 2 steps
step 1
follow instructions on this link
http://www.websences.com/dpkg-reconfigure-x11-common/

Code: Select all

dpkg-reconfigure x11-common

Posted on April 19, 2017
After X server update 1.18.4 `su — pi -c “startx” &` not working anymore

Jessie updated xserver-xorg-core to 1.18.4 from 1.17.2, to fix the problem

sudo dpkg-reconfigure x11-common

update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults

sudo apt-get install xserver-xorg-legacy -y

sudo nano /etc/X11/Xwrapper.config

#Change console to anybody

allowed_users=anybody
step 2
edit

Code: Select all

sudo nano /etc/X11/xinit/xinitrc


your file will look something like this

Code: Select all

#!/bin/sh

# /etc/X11/xinit/xinitrc
#
# global xinitrc file, used by all X sessions started by xinit (startx)

# invoke global X session script
. /etc/X11/Xsession
put a # in front off the line containing
. /etc/X11/Xsession
as this will launch the default user interface

after that put

Code: Select all

#~your_user/.xinitrc
/usr/bin/gambas3
replace youre_user with
pi
ore any othere user
and replace
/usr/bin/gambas3
with what ever youre command is fore java it can be

Code: Select all

sudo java -jar path to youre -jar file and launch options

Return to “Beginners”