How to Automatically Start an Application That Needs X in Linux

How do I automatically start an application that needs X in Linux

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.

How to automatically start and advance a few steps in an application in background in linux?

For now Genymotion allows you to start a VM from the command line, by calling the "player" binary, and passing the VM name as a parameter.

You could write a shell script that:

  • run: <GENYMOTION PATH>/player --vm-name <VM NAME>,
  • wait some seconds for the VM to boot: sleep 10,
  • then use adb to start your Application: adb shell am start -n com.whatsapp/com.whatsapp.Main

Luckily, no need to simulate clicks for this.

How to run a shell script at startup

The file you put in /etc/init.d/ have to be set to executable with:

chmod +x /etc/init.d/start_my_app

As pointed out by @meetamit, if it still does not run you might have to create a symbolic link to the file in /etc/rc.d/

ln -s /etc/init.d/start_my_app /etc/rc.d/

Please note that on the latest versions of Debian, this will not work as your script will have to be LSB compliant (provide at least the following actions: start, stop, restart, force-reload, and status):
https://wiki.debian.org/LSBInitScripts

As a note, you should always use the absolute path to files in your scripts instead of the relative one, it may solve unexpected issues:

/var/myscripts/start_my_app

Finally, make sure that you included the shebang on top of the file:

#!/bin/sh

Have my GTK application started on startup on Linux

Create a .desktop file of your application, and put it to /etc/xdg/autostart/ for each user, or to $HOME/.config/autostart/ for current user.

If you want to load that application as root for general users, you may choose to use gksu or other tools to authorize priviledge.

Alternatively, you can see how network-manager is designed. It inits network-manager module as a init-script when system starts, and loads nm-applet, which is GUI for ordinary user, when a user session loads. Thus, network-manager can be managed on all the desktop environment (like Gnome, KDEE, xfce...) by desktop users.

Qt C++ application: self autostart installation in Linux

You can add application in various ways.

  1. Via linux init system. For newest linux OS systemd is a standard. In this case your need to create systemd unit for your application
  2. Via desktop manager, such as gnome, kde and possible others. In this case you need also create specification for autostarting your app.
  3. Via bash files

I think, prefered way via systemd unit, because now this is standard way for starting process at boot time and for special user, if need.

Qt application GUI -- automatic start -- linux

You very probably need some X window manager to run your Qt application, perhaps even some desktop environment (i.e. you want EWMH & ICCCM compliance), and you obviously need a running X11 server (usually Xorg). So you could manage to have some xinitrc for all that.

Notice that some session -or display- managers like lightdm can be configured to start some special sessions.

In all cases, you need a lot more than just your application to be running, and you certainly need to understand in detail what your Qt application really requires (mostly thru Qt libraries). Learn more about the X11 protocol. See also freedesktop.org.

Run Qt application on startup as Linux daemon

Is your program a GUI application or does it work without GUI?

Why don't you just background it within the init script using &?



Related Topics



Leave a reply



Submit