How to start a service automatically when Arch Linux boots?

Solution 1:

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).

Solution 2:

xbindkeys is not a service, which would instead require the use of systemctl.

However, xbindkeys has, like just about anything in Arch, a very good wiki page, here, which, states, among other things:

Once you're done configuring your keys, edit your ~/.xinitrc and place

 xbindkeys

before the line that starts your window manager or DE.

You should really start reading the Wiki, it is truly well-written, so much so that I read it even when I have to add/modify configurations to my other, non-Arch Linux systems.