Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't invoke systemctl --user. #18

Open
tommyvdv opened this issue Feb 27, 2018 · 8 comments
Open

Can't invoke systemctl --user. #18

tommyvdv opened this issue Feb 27, 2018 · 8 comments
Assignees
Milestone

Comments

@tommyvdv
Copy link

I'm no expert on systemctl or its related technology, far from it.
I do know that systemctl and systemctl --user are two separated concepts on the linux distro I'm working with.

At first glance it doesn't seem possible to add the option user to the command.

Running ->getService('test') works if the unit test is configured as a system unit.

$ systemctl status test

Running ->getService('test') works if the unit test is configured as a user unit but throws an (expected) UnitNotFoundException exception.

$ systemctl --user status test

I hope this is on the road map or, better yet, I'm just missing the obvious solution.

@icanhazstring
Copy link
Owner

Hi @tommyvdv

u guessed correct. Currently the lib does not support the parameter --user. This has to be added to invoke systemctl on a user level.

I will mark this as enhancement and will try to implement it asap :)
Thanks for the feedback tho. 👍

@icanhazstring icanhazstring added this to the v1.0 milestone Feb 27, 2018
@icanhazstring
Copy link
Owner

Additional information: https://wiki.archlinux.org/index.php/Systemd/User

@tommyvdv
Copy link
Author

Hi @icanhazstring
Thanks for confirming this and for sharing your project.
Here's looking forward to v1.0.

@icanhazstring
Copy link
Owner

icanhazstring commented Mar 2, 2018

@tommyvdv is just pushed a commit into dev branch 1.x.
This should add the ability to switch the scope of the SystemCtl instance to either user oder system.

$systemCtl = new SystemCtl();
$systemCtl->getService(...); // same as $systemCtl->system()->getService()
$systemCtl->user()->getService(...); // uses the --user argument on systemctl binary

You can switch the scope with each call. Just remember to use ->user() oder ->system() before getting the unit you want.

You can check this out by using current dev branch.

$ composer require icanhazstring/systemctl-php:dev-1.x

Hope this works for you. I will try to finish the next milestone coming this weekend and tag the finished v1.0.

@icanhazstring
Copy link
Owner

Hi @tommyvdv can you confirm the implementation. So i can close the issue. And possibly tag a release for it.

@tommyvdv
Copy link
Author

tommyvdv commented Jul 7, 2018

I've tried to test this on an ubuntu 16.04 box but can't confirm it's working.
While I can get a system service using ->getService('apache2.service') and list the units using ->listUnits(), it seems ->user()->listUnits() returns an empty array or throws a UnitNotFoundException when using ->user()->getService(…).

Running the commands directly I can retrieve a couple of services like obex.service from the --user instance;

$ systemctl --user status obex
● obex.service - Bluetooth OBEX service
   Loaded: loaded (/usr/lib/systemd/user/obex.service; disabled; vendor preset: enabled)
   Active: inactive (dead)

I'm probably going about this the wrong way but in case I'm not; hope this helps.

@icanhazstring
Copy link
Owner

Hm. Thanks for the feedback tho. I will look into this.

@icanhazstring
Copy link
Owner

icanhazstring commented Jul 17, 2018

Good news @tommyvdv. I probably found out what went wrong.
The problem was, that there is the possibility that a unit is not running and my implementation does not cover getting loaded but inactive units. But I figured a way of supporting this.

Bad news tho, I discovered some minor other bugs on the way which need attention as well ;)

@icanhazstring icanhazstring self-assigned this Jul 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants