PRATEEK AGRAWAL
PRATEEK AGRAWAL

Reputation: 357

Run the application at startup in linux

I am making a Linux application. This application synchronizes the client's files and folders with cloud. There is folder in home directory in which all the files from cloud will be synchronized. I want that the application should be started in background after boot and work in background automatically. How can I do it?

Upvotes: 0

Views: 1046

Answers (2)

Kevin Boone
Kevin Boone

Reputation: 4307

If you have what is essentially a single-user system, you can use init/systemd to start background processes as a nominated, unprivileged user. However, that isn't the usual use of these techniques.

In a multi-user, graphical system, you probably want user-related background processes to start when the user's desktop session starts. Not only is this (usually) the proper timing for such operations, it allows multiple users to be supported.

The various graphical desktops available for Linux all provide slightly different ways to run user applications at login. It's probably impossible to find a method that will work for all desktops. For full coverage, you probably need to implement something that detects what desktop is in use, and uses the method appropriate to that desktop.

However, many desktops respect the use of $HOME/.config/autostart/. Files in that directory should have a .desktop extension, and be of the same format as application launchers. For example:

[Desktop Entry]
Name=MyThingie
GenericName=foo
Comment=foo
Exec=/path/to/my/executable
Terminal=false
Type=Application
Icon=foo
Categories=Network;FileTransfer;
StartupNotify=false

Upvotes: -1

Alessandro Romano
Alessandro Romano

Reputation: 762

If you have systemd you can create a service as shown here.

Otherwise you have to use init.

Upvotes: 3

Related Questions