I'm trying to get a Qt application to launch immediately after booting up. When booted, the Linux image does nothing more than launch an X server and a terminal. It also has the cron daemon running in the background. Obviously, my Qt application needs the X server to be running to do anything.

I've seen a similar question for Red Hat and SUSE Linux.

However, I don't see this working for my image.

I'm wondering if there is a standard way in Linux/UNIX to make a GUI application start immediately after the X Server.

[sj755@localhost X11]$ tree /etc/X11/
|-- functions
|-- Xdefaults
|-- Xinit
|-- Xinit.d
|   |-- 01xrandr
|   |-- 11zaurus
|   |-- 12keymap
|   |-- 40xmodmap
|   |-- 50setdpi
|   |-- 55xScreenSaver
|   |-- 60xXDefaults
|   |-- 89xTs_Calibrate
|   `-- 98keymap-fixup
|-- xmodmap
|   |-- a716.xmodmap
|   |-- collie.xmodmap
|   |-- default.xmodmap
|   |-- h1910.xmodmap
|   |-- h2200.xmodmap
|   |-- h6300.xmodmap
|   |-- hx4700.xmodmap
|   |-- keyboardless.xmodmap
|   |-- omap5912osk.xmodmap
|   |-- poodle.xmodmap
|   |-- shepherd.xmodmap
|   |-- simpad.xmodmap
|   |-- slcXXXX.xmodmap
|   |-- xmodmap-invert
|   |-- xmodmap-left
|   |-- xmodmap-portrait
|   `-- xmodmap-right
|-- xorg.conf
|-- Xserver
|-- xserver-common
|-- Xsession
`-- Xsession.d
    |-- 60xXDefaults
    |-- 89xdgautostart
    `-- 90xXWindowManager

3 directories, 36 files

root@devboard:~# cat /etc/X11/Xsession.d/90xXWindowManager
if [ -x $HOME/.Xsession ]; then
    exec $HOME/.Xsession
elif [ -x /usr/bin/x-session-manager ]; then
    exec /usr/bin/x-session-manager
    exec /usr/bin/x-window-manager

# Very simple session manager for Mini X

# Uncomment below to enable parsing of debian menu entrys
# export MB_USE_DEB_MENUS=1 

if [ -e $HOME/.mini_x/session ]
exec $HOME/.mini_x/session

if [ -e /etc/mini_x/session ]
exec /etc/mini_x/session

if [ -d "$MINI_X_SESSION_DIR" ]; then
    # Execute session file on behalf of file owner
    find $MINI_X_SESSION_DIR -type f | while read SESSIONFILE; do
        set +e
        USERNAME=`stat -c %U $SESSIONFILE`
        # Using su rather than sudo as latest 1.8.1 cause failure [YOCTO #1211]
#       su -l -c '$SESSIONFILE&' $USERNAME
        sudo -b -i -u $USERNAME $SESSIONFILE&
        set -e

# This resolution is big enough for hob2's max window size.
xrandr -s 1024x768

# Default files to run if $HOME/.mini_x/session or /etc/mini_x/session
# don't exist. 

exec matchbox-window-manager

Have a look at /etc/X11/xinit/xinitrc (this may be different places on different systems) to see what files it sources. Generally, this will have an if..elif..else structure, so that only one initialization file is read, with $HOME/.Xclients prioritized then /etc/X11/xinit/Xclients. That's almost certainly where the terminal that appears comes from (I am presuming you do not have a desktop environment installed or anything).

Anyway, if you just want to run a single GUI app, create (or modify) an Xclients file like this:



This should be executable. It's pretty much a normal shell script, I believe, so you can have more stuff in there, although obviously not backgrounding a GUI app will block execution at that point.

[later addition]

Your installation doesn't have exactly those files, but it does have an /etc/X11/Xinit.d and if you look, I am sure those are short shell scripts and they are sourced from somewhere, probably one of the files in /etc/X11 -- Xsession, Xserver, or xserver-common. You might want to check if $XINITRC is defined in your environment; that will be a clue.

Your best bet is probably to just create a $HOME/.Xclients file (or as jofel mentions, $HOME/.xinitrc, which is probably more universal) and try it -- exactly that spelling and case, with a leading dot, and it should be set chmod 755 (the group and other permissions may not matter). Almost certainly this will be sourced from somewhere properly.

You can put files in /etc/X11/Xinit.d yourself, but doing it for this purpose is not a good idea because yours should run last and block further execution. So have a look at the scripts in /etc/X11 (again: Xsession, etc., they don't have a .sh suffix) and try to figure out in what order they all chain together. It is also likely that somewhere one of them checks for an Xclients file, eg via something like

if [ -x /some/path/Xclients ]; then

$HOME may also be used, and .xinitrc. Which is why creating at least one of these variations should work (write the file and move around/rename it if at first you don't succeed). To summarize: prime candidates for the name: .xinitrx and .Xclients, in either $HOME or /etc/X11/, but if in the later, ditch the leading dot.

  • I've updated my question, showing the /etc/X11 directory tree. I don't see an xinitrc file. – sj755 Jul 18 '13 at 16:17
  • 1
    @sj755: Okay, read what I've added after "later addition". – goldilocks Jul 18 '13 at 16:51
  • I found a file of interest. I've posted its contents. It seems to execute a file called $HOME/.Xsessions. I tried putting my script in that. It seems I broke the X Server. Luckily it's only an embedded Linux device and I can quickly recreate the image. – sj755 Jul 18 '13 at 17:18
  • 1
    :( $HOME/.Xsessions looks to be it to me. I'm not sure what you mean by "broke" the X Server -- do you have logging available? If so check /var/log/Xorg.0.log. – goldilocks Jul 18 '13 at 17:30
  • 1
    @sj755: That's exactly right. Try removing/commenting out matchbox-terminal& and replacing matchbox-window-manager with your app. You may not need a window manager running in order to get your QT code to fullscreen the app, so that is worth trying to save a bit of RAM (this will also mean the window can't be manipulated by the user, if there is any interaction applicable). Otherwise do with &, like the terminal. – goldilocks Jul 18 '13 at 18:10

You can add the command to the $HOME/.xinitrc of the user which starts the X server.

Need to be an executable $HOME/.xinitrc shell script (first line #!/bin/sh and chmod +x $HOME/.xinitrc).


Firstly, it's not necessarily obvious that "my Qt application needs the X server to be running to do anything" - I have successfully run Qt5 applications with the linuxfb backend from upstart. If you can do that, you'll get faster startup and lower memory use than going via X. On the other hand, you might want it to start X11 client programs, or need a window manager, so it's not for everyone.

Assuming for now that your application does need an X server, look at the nodm display manager. This is designed for embedded applications; I use it for my MythTV frontend. It's much cleaner than meddling with the scripts in /etc/X11/, and gives you the ability to have different setups for different users, which may be handy during development.

It's pretty easy to use; on a Debian install, just edit /etc/default/nodm to enable nodm and specify the required username. Other defaults are probably okay.

Then give that user a suitable ~/.xinitrc - in the simplest case, you could make it a symlink to your application. But it's more likely to be a short /bin/sh script that maybe sets a background, installs a keymap, starts a screensaver, and any other niceties you fancy before exec myapplication.

Hint - replace the last line with exec xterm whilst you're working on it - that can be pretty useful for trying things out.

  • nodm is the way to go IMO. We use this for large deployments of kiosk applications and it works a charm. Also solid advice on .xinitrc – Lennart Rolland Sep 20 '16 at 22:15

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.