I want a specific service of OpenRC to run after my user login through agetty, LightDM (display manager), or any other way.

This is because I have a emacs daemon running as OpenRC service for my specific user and I need this service to start only after a dbus session is created. One way to accomplish this is to run emacs daemon after dbus-launch (related history) runs my main session (currently XFCE session), which for instance happens after a login through the LightDM display manager .

What I do as workaround is: restart emacs after login with my user to initialize correctly dbus integration with emacs. But this is just painful. There must be a better way to do that.

  • I'm not sure I understand, but maybe ~/.profile or ~/.xinitrc?
    – n.caillou
    Nov 27, 2017 at 12:05
  • I can run services with cow powers (root) on ~/.profile or ~/.xinitrc without prompting for auth (sudo)? Because if I start "manually" the OpenRC services, I need to run as root as usual (su or sudo). Nov 27, 2017 at 12:36

3 Answers 3


The Gentoo wiki has a page describing various ways of launching user services on a system that uses OpenRC, but you could adapt any of those methods to your system even if you don't use Gentoo. There are a few different options, depending on what you need:

  • Use the autostart functionality of your desktop environment, if available. (I don't use XFCE so I'm not sure if it has this functionality.) This is probably the easiest option to set up if it works, especially if your service needs to connect to the DBUS daemon because it will automatically inherit the environment variables that tell it how to access DBUS from XFCE. However, it will only work when you log in graphically, not with agetty, so it sounds like it's not what you want.

  • Add the daemon as a regular OpenRC service (which means creating a script for it in /etc/init.d/) and set up PAM to start and stop the service when you log in or log out. This will start the service even if you log in with a non-graphical method like agetty or SSH. However, if you do this, the service will not have access to DBUS-related environment variables.

    You might be able to detect the DBUS-related parameters dynamically - there's a script in the wiki page showing how you could try to do that - but it's not the most robust thing. And of course, that relies on there being a running DBUS daemon to connect to, which will only be the case if it has been launched by your desktop environment. If it hasn't, then you need to figure out what your service should do (e.g. should it fail? should it start its own DBUS daemon?) and implement that.

  • Use a separate service manager that can run services from a custom directory. (The wiki page uses runsvdir as an example of this, but any other program that does the same thing should be acceptable.) You can start the service manager in either of the ways previously mentioned (an OpenRC service controlled by PAM, or your desktop environment's autostart), or run it from one of your shell init files, or have it as an OpenRC service that isn't controlled by PAM and just starts when your system boots up like everything else, or so on. Then you can define a service for your emacs daemon in this custom directory, and put commands in some suitable initialization file (shell startup, PAM, xsession, etc.) to tell the separate service manager to start and stop that service as needed.

    This way probably gives you the most flexibility in how you control when your emacs daemon runs, but it has the same issues with DBUS previously mentioned: the separate service manager will not have access to any DBUS-related environment variables unless you start it from your desktop environment's autostart. So you'll probably need to use some sort of dynamic detection of DBUS connection parameters if you need them.

Depending on what exactly you need, one or another of these approaches might be right for you. Whichever one you pick, you can find more detail on how to implement it in the linked wiki page.


Yes, it's possible. You just have to add sudo rc-service yourservice start to your user's .bashrc.

  • Using sudo on .bashrc... I don't want do that for a couple of reasons. Thanks for the attempt, but sorry. This is not what I want. Nov 27, 2017 at 12:34

rc-update add <service> <runlevel>

source: https://wiki.gentoo.org/wiki/OpenRC_to_systemd_Cheatsheet

  • 1
    This answer doesn't accomplish the goal. Note that the Op wanted to start a service at login, not boot. Oct 3, 2019 at 19:24
  • This idea could potentially work, if the OP were to create a new runlevel which was entered at login in .bashrc, and it could possibly be an easier to maintain solution than adding rc-service commands in .bashrc; I'm not sure if this idea is the respondent's original intent, but it's a possible approach to the problem
    – Morgan H
    Jan 12, 2020 at 19:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .