4

I'm porting some Qt Windows/VC++ code to Linux/GCC. The application can add it's own shortcut to the Windows Autostart folder so the application starts after login.

I want to do the same in Linux. I'm using Kubuntu 15.10 but the solution should work for virtually all (or at least most) Linux variants out there. And it should work without super user rights (or it should request the rights automatically).

I searched the web and found two solutions:

  1. Add a desktop entry file to $HOME/.config/autostart
  2. Add a symbolic link to /etc/init.d/

Will they both work in all Linux distributions? What are the differences? Which is to be preferred?

Also I would like to know if I should do that by programmatically running a shell command or if there is some native API I could use in C/C++ (including easy error detection).

4
  • 1
    Are you aware how those two things you mention differ? Dec 14, 2015 at 7:09
  • "the solution should work for virtually all (or at least most) Linux variants out there" - that's almost impossible. Dec 14, 2015 at 7:41
  • @Ulrich. Not exactly. I assume that the home based solution is user specific while the other one is system wide, is this correct? Maybe there are also differences in necessary user rights and/or when the application is started? Dec 14, 2015 at 7:53
  • Correct, anything under /etc is system-wide, under /home it is user-specific. That also means that if no user is logged in, nothing is running and if two users are logged in, the same program could be started twice. It seems that you want at most one program running in the system, since it always runs as root. However, that would have to run without an X session. If you need a UI, you could also install the application with SUID-bit set and then use a per-user autostart. Lastly, you could also start a server on demand, e.g. via xinetd if it operates as a networked server. Dec 16, 2015 at 7:20

2 Answers 2

3

I have put project in GitHub for managing auto-start feature in different OS. It's written in Qt. Please check it and let me know if you have any problem using it: https://github.com/b00f/qautostart

0
1

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.

6
  • If I understand correctly I would create some new link or file by executing a shell command for each of these solutions. So there is no such thing like a C++ API for that task? Dec 14, 2015 at 8:02
  • That GUI applications needs user interaction to do anything useful. This is why I planned to start it after login. Could it generate any problem when starting it before login (on boot) using systemd? Dec 14, 2015 at 10:55
  • 1
    @Silicomancer your can specify systemd unit for user or via desktop manager file specialization in this case.
    – synacker
    Dec 14, 2015 at 14:05
  • systemd seems to work well. I tried to use D-Bus for systemd control but it looks like user session D-Bus of systemd is buggy in some way. So I am using comand line tools instead. Dec 21, 2015 at 20:51
  • 1
    No, I am creating the .service file using normal file operations. But I tried to do the necessary enabling/disabling of the unit using D-Bus. However as I mentioned, it doesn't work for user units due to D-Bus problems. For system units it works. Dec 22, 2015 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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