{"action":"created","issue":{"url":"https://api.github.com/repos/systemd/systemd/issues/1156","labels_url":"https://api.github.com/repos/systemd/systemd/issues/1156/labels{/name}","comments_url":"https://api.github.com/repos/systemd/systemd/issues/1156/comments","events_url":"https://api.github.com/repos/systemd/systemd/issues/1156/events","html_url":"https://github.com/systemd/systemd/issues/1156","id":105020625,"number":1156,"title":"I need a pre_remove scriptlet to check if users have a user service enabled and stop it for them BEFORE the package manager removes the executable... how?","user":{"login":"graysky2","id":534822,"avatar_url":"https://avatars.githubusercontent.com/u/534822?v=3","gravatar_id":"","url":"https://api.github.com/users/graysky2","html_url":"https://github.com/graysky2","followers_url":"https://api.github.com/users/graysky2/followers","following_url":"https://api.github.com/users/graysky2/following{/other_user}","gists_url":"https://api.github.com/users/graysky2/gists{/gist_id}","starred_url":"https://api.github.com/users/graysky2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/graysky2/subscriptions","organizations_url":"https://api.github.com/users/graysky2/orgs","repos_url":"https://api.github.com/users/graysky2/repos","events_url":"https://api.github.com/users/graysky2/events{/privacy}","received_events_url":"https://api.github.com/users/graysky2/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-05T10:53:09Z","updated_at":"2015-09-06T00:13:30Z","closed_at":"2015-09-06T00:13:30Z","body":"I need a package manager to call a pre_remove scriptlet that will use `systemd --user` to check if users have a user service active, and if so, stop it for them before removing the executable.  Below is what I came up with but when root (the package manager) runs it, none of the systemctl --user commands work since root has no D-Bus connection.\r\n\r\nIs there an alternative or tweak to my code to achieve the expected result?\r\n\r\n```\r\nusers=$(getent passwd | grep home | awk -F: '{print $1}' | awk 1 ORS=' ')\r\nfor i in $users; do\r\n running=\"$(su $x -c 'systemctl --user is-active psd')\"\r\n if [[ \"$running\" = \"active\" ]]; then\r\n  su \"$i\" -c 'systemctl --user stop psd.service'\r\n fi\r\ndone\r\n```\r\n\r\nOutput on a 2-user system when executed as root:\r\n```\r\nFailed to get D-Bus connection: No such file or directory\r\nFailed to get D-Bus connection: No such file or directory\r\n```\r\n\r\nThank you."},"comment":{"url":"https://api.github.com/repos/systemd/systemd/issues/comments/138012444","html_url":"https://github.com/systemd/systemd/issues/1156#issuecomment-138012444","issue_url":"https://api.github.com/repos/systemd/systemd/issues/1156","id":138012444,"user":{"login":"poettering","id":2130732,"avatar_url":"https://avatars.githubusercontent.com/u/2130732?v=3","gravatar_id":"","url":"https://api.github.com/users/poettering","html_url":"https://github.com/poettering","followers_url":"https://api.github.com/users/poettering/followers","following_url":"https://api.github.com/users/poettering/following{/other_user}","gists_url":"https://api.github.com/users/poettering/gists{/gist_id}","starred_url":"https://api.github.com/users/poettering/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/poettering/subscriptions","organizations_url":"https://api.github.com/users/poettering/orgs","repos_url":"https://api.github.com/users/poettering/repos","events_url":"https://api.github.com/users/poettering/events{/privacy}","received_events_url":"https://api.github.com/users/poettering/received_events","type":"User","site_admin":false},"created_at":"2015-09-06T00:13:30Z","updated_at":"2015-09-06T00:13:30Z","body":"This is not supported, sorry. privileged code should not connect and be client to unprivileged client code. That's simply the wrong way round.\r\n\r\nI fear what you are trying to do is not supported. It's not a problem intrinsic to systemd though, it's the way how things are on UNIX/Linux with package managers, for any program.\r\n\r\nAlso, please understand that this is a bug tracker, not a help forum. Please redirect questions like yours to the systemd mailing list instead. Thanks!"}}