# Linux – How to start a service automatically when Arch Linux boots

arch linux

I have done a bit of research trying to figure this out only to find various options that seem very convoluted and complicated just to start one service, which is all I need to do.

Basically, I am trying to start xbindkeys whenever the desktop environment starts up (or whenever the user logs in).

What are simple options to do this?

Be careful about the type of service you're trying to start. You correctly determined that xbindkeys should start along with the desktop environment, as it needs access to your X11 display, which "start on boot" services would not have. Many people forget this.

In most desktop environments, create ~/.config/autostart/xbindkeys.desktop according to the XDG Autostart specification:

[Desktop Entry]
Type=Application
Exec=xbindkeys


Usually this can be done through cinnamon-session-properties or similar.

Another method is to put the command in the ~/.xprofile script, which is run by most display managers (GDM, KDM, LXDM, LightDM):

xbindkeys &


If you are using only startx, put the same line in your ~/.xinitrc instead, before the part which starts your desktop environment. Same applies to display managers that invoke startx, such as SLiM.

Some services, including xbindkeys, "detach" themselves so the & is not strictly required. However, it won't hurt, and could possibly make startup faster since bash detaches before even starting the process. On the other hand, there are some situations where it would hurt – that is, when it's necessary to know when the service has fully initialized.

System-wide services, on the other hand, should be started as systemd services, by creating an /etc/systemd/system/<name>.service unit file. They start early and do not have access to any X11 display (and often start before the display manager does).