I have a Debian package which installs my software and it needs to start two applications in post install script. First one is daemon and the second one is a background process both are managed with systemd. The problem is that I run sudo dpkg -i ... , and it fails to start user level unit with the following error: Failed to connect to bus: No such file or directory. It is a normal practice to start scripts after installation, but the sudo rights permit me to start my script. Maybe I'm missing something. Someone knows how to overcome this problem?

The command which is use to start script: systemctl --user start test.service. When it is executed from installer it actually becomes sudo systemctl --user start test.service.(Same doesn't work from terminal).


Ok, I have managed to fix the issue. It was not an issue to begin with, just my lack of knowledge about DBus sessions and how do they work. I hope that my answer will help someone.

When you will open terminal and execute systemctl --user command unit everything will be fine, but when you will try to do under sudo or switch to another user using su command, you will fail with error that I had:

Failed to connect to bus: No such file or directory.

The problem is that systemctl to connect to user sessions uses dbus session address which is set in DBUS_SESSION_ADDRESS env variable. When you do sudo or su you get a very limited environment, simply you are missing DBUS_SESSION_ADDRESS and other env variables. So when you get similar errors, check your environment perhaps something important is missing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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