Skip to content

Can't invoke systemctl --user. #18

Description

@tommyvdv

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.

Activity

  1. icanhazstring commented on Feb 27, 2018

    @icanhazstring
    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. 👍

  2. added this to the milestone on Feb 27, 2018
  3. icanhazstring commented on Feb 27, 2018

    @icanhazstring
    Owner
  4. tommyvdv commented on Feb 27, 2018

    @tommyvdv
    Author

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

  5. icanhazstring commented on Mar 2, 2018

    @icanhazstring
    Owner

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

  6. icanhazstring commented on Jul 6, 2018

    @icanhazstring
    Owner

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

  7. tommyvdv commented on Jul 7, 2018

    @tommyvdv
    Author

    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.

  8. icanhazstring commented on Jul 7, 2018

    @icanhazstring
    Owner

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

  9. icanhazstring commented on Jul 17, 2018

    @icanhazstring
    Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions