Code Monkey home page Code Monkey logo

pystemd's Introduction

Systemd

System and Service Manager

Semaphore CI 2.0 Build Status
Coverity Scan Status
OSS-Fuzz Status
CIFuzz
CII Best Practices
CentOS CI - CentOS 9
CentOS CI - Arch
CentOS CI - Arch (sanitizers)
Fossies codespell report
Weblate
Coverage Status
Packaging status
OpenSSF Scorecard

Details

Most documentation is available on systemd's web site.

Assorted, older, general information about systemd can be found in the systemd Wiki.

Information about build requirements is provided in the README file.

Consult our NEWS file for information about what's new in the most recent systemd versions.

Please see the Code Map for information about this repository's layout and content.

Please see the Hacking guide for information on how to hack on systemd and test your modifications.

Please see our Contribution Guidelines for more information about filing GitHub Issues and posting GitHub Pull Requests.

When preparing patches for systemd, please follow our Coding Style Guidelines.

If you are looking for support, please contact our mailing list, join our IRC channel #systemd on libera.chat or Matrix channel

Stable branches with backported patches are available in the stable repo.

We have a security bug bounty program sponsored by the Sovereign Tech Fund hosted on YesWeHack

pystemd's People

Contributors

aleivag avatar amyreese avatar dabcoder avatar davide125 avatar irregulator avatar javierhonduco avatar jrmithdobbs avatar kfix avatar kylelaker avatar mibpl avatar michel-slm avatar mokomull avatar mvismonte avatar onionymous avatar samueldudley avatar simpkins avatar stefal avatar tacaswell avatar zpao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pystemd's Issues

Python 3.11 support

I can't install pystemd with Python 3.11 because of the following error: pystemd/journal.c:214:12: fatal error: longintrepr.h: No such file or directory. I found a similar solved issue in aio-libs/aiohttp#6600. Unfortunately, I never worked with CPython or Cython, so I can't say more about this error.

This is the pip install pystemd command output:

Collecting pystemd
  Using cached pystemd-0.10.0.tar.gz (277 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: pystemd
  Building wheel for pystemd (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [43 lines of output]
      /home/osservatorio/venv/lib/python3.11/site-packages/setuptools/config/setupcfg.py:508: SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead.
        warnings.warn(msg, warning_class)
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-cpython-311
      creating build/lib.linux-x86_64-cpython-311/pystemd
      copying pystemd/run.py -> build/lib.linux-x86_64-cpython-311/pystemd
      copying pystemd/exceptions.py -> build/lib.linux-x86_64-cpython-311/pystemd
      copying pystemd/base.py -> build/lib.linux-x86_64-cpython-311/pystemd
      copying pystemd/__version__.py -> build/lib.linux-x86_64-cpython-311/pystemd
      copying pystemd/utils.py -> build/lib.linux-x86_64-cpython-311/pystemd
      copying pystemd/__init__.py -> build/lib.linux-x86_64-cpython-311/pystemd
      creating build/lib.linux-x86_64-cpython-311/pystemd/systemd1
      copying pystemd/systemd1/manager.py -> build/lib.linux-x86_64-cpython-311/pystemd/systemd1
      copying pystemd/systemd1/unit.py -> build/lib.linux-x86_64-cpython-311/pystemd/systemd1
      copying pystemd/systemd1/unit_signatures.py -> build/lib.linux-x86_64-cpython-311/pystemd/systemd1
      copying pystemd/systemd1/__init__.py -> build/lib.linux-x86_64-cpython-311/pystemd/systemd1
      creating build/lib.linux-x86_64-cpython-311/pystemd/machine1
      copying pystemd/machine1/manager.py -> build/lib.linux-x86_64-cpython-311/pystemd/machine1
      copying pystemd/machine1/machine.py -> build/lib.linux-x86_64-cpython-311/pystemd/machine1
      copying pystemd/machine1/__init__.py -> build/lib.linux-x86_64-cpython-311/pystemd/machine1
      creating build/lib.linux-x86_64-cpython-311/pystemd/DBus
      copying pystemd/DBus/__init__.py -> build/lib.linux-x86_64-cpython-311/pystemd/DBus
      copying pystemd/RELEASE -> build/lib.linux-x86_64-cpython-311/pystemd
      copying pystemd/daemon.pyi -> build/lib.linux-x86_64-cpython-311/pystemd
      copying pystemd/utils.pyi -> build/lib.linux-x86_64-cpython-311/pystemd
      copying pystemd/base.pyi -> build/lib.linux-x86_64-cpython-311/pystemd
      copying pystemd/dbuslib.pyi -> build/lib.linux-x86_64-cpython-311/pystemd
      copying pystemd/__init__.pyi -> build/lib.linux-x86_64-cpython-311/pystemd
      copying pystemd/systemd1/manager.pyi -> build/lib.linux-x86_64-cpython-311/pystemd/systemd1
      copying pystemd/systemd1/unit.pyi -> build/lib.linux-x86_64-cpython-311/pystemd/systemd1
      running build_ext
      building 'pystemd.journal' extension
      creating build/temp.linux-x86_64-cpython-311
      creating build/temp.linux-x86_64-cpython-311/pystemd
      x86_64-linux-gnu-gcc -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -I/home/osservatorio/venv/include -I/usr/include/python3.11 -c pystemd/journal.c -o build/temp.linux-x86_64-cpython-311/pystemd/journal.o
      pystemd/journal.c:214:12: fatal error: longintrepr.h: No such file or directory
        214 |   #include "longintrepr.h"
            |            ^~~~~~~~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pystemd
  Running setup.py clean for pystemd
Failed to build pystemd
Installing collected packages: pystemd
  Running setup.py install for pystemd ... error
  error: subprocess-exited-with-error

  × Running setup.py install for pystemd did not run successfully.
  │ exit code: 1
  ╰─> [45 lines of output]
      /home/osservatorio/venv/lib/python3.11/site-packages/setuptools/config/setupcfg.py:508: SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead.
        warnings.warn(msg, warning_class)
      running install
      /home/osservatorio/venv/lib/python3.11/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
        warnings.warn(
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-cpython-311
      creating build/lib.linux-x86_64-cpython-311/pystemd
      copying pystemd/run.py -> build/lib.linux-x86_64-cpython-311/pystemd
      copying pystemd/exceptions.py -> build/lib.linux-x86_64-cpython-311/pystemd
      copying pystemd/base.py -> build/lib.linux-x86_64-cpython-311/pystemd
      copying pystemd/__version__.py -> build/lib.linux-x86_64-cpython-311/pystemd
      copying pystemd/utils.py -> build/lib.linux-x86_64-cpython-311/pystemd
      copying pystemd/__init__.py -> build/lib.linux-x86_64-cpython-311/pystemd
      creating build/lib.linux-x86_64-cpython-311/pystemd/systemd1
      copying pystemd/systemd1/manager.py -> build/lib.linux-x86_64-cpython-311/pystemd/systemd1
      copying pystemd/systemd1/unit.py -> build/lib.linux-x86_64-cpython-311/pystemd/systemd1
      copying pystemd/systemd1/unit_signatures.py -> build/lib.linux-x86_64-cpython-311/pystemd/systemd1
      copying pystemd/systemd1/__init__.py -> build/lib.linux-x86_64-cpython-311/pystemd/systemd1
      creating build/lib.linux-x86_64-cpython-311/pystemd/machine1
      copying pystemd/machine1/manager.py -> build/lib.linux-x86_64-cpython-311/pystemd/machine1
      copying pystemd/machine1/machine.py -> build/lib.linux-x86_64-cpython-311/pystemd/machine1
      copying pystemd/machine1/__init__.py -> build/lib.linux-x86_64-cpython-311/pystemd/machine1
      creating build/lib.linux-x86_64-cpython-311/pystemd/DBus
      copying pystemd/DBus/__init__.py -> build/lib.linux-x86_64-cpython-311/pystemd/DBus
      copying pystemd/RELEASE -> build/lib.linux-x86_64-cpython-311/pystemd
      copying pystemd/daemon.pyi -> build/lib.linux-x86_64-cpython-311/pystemd
      copying pystemd/utils.pyi -> build/lib.linux-x86_64-cpython-311/pystemd
      copying pystemd/base.pyi -> build/lib.linux-x86_64-cpython-311/pystemd
      copying pystemd/dbuslib.pyi -> build/lib.linux-x86_64-cpython-311/pystemd
      copying pystemd/__init__.pyi -> build/lib.linux-x86_64-cpython-311/pystemd
      copying pystemd/systemd1/manager.pyi -> build/lib.linux-x86_64-cpython-311/pystemd/systemd1
      copying pystemd/systemd1/unit.pyi -> build/lib.linux-x86_64-cpython-311/pystemd/systemd1
      running build_ext
      building 'pystemd.journal' extension
      creating build/temp.linux-x86_64-cpython-311
      creating build/temp.linux-x86_64-cpython-311/pystemd
      x86_64-linux-gnu-gcc -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -I/home/osservatorio/venv/include -I/usr/include/python3.11 -c pystemd/journal.c -o build/temp.linux-x86_64-cpython-311/pystemd/journal.o
      pystemd/journal.c:214:12: fatal error: longintrepr.h: No such file or directory
        214 |   #include "longintrepr.h"
            |            ^~~~~~~~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> pystemd

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

Thanks for the support!

AttributeError: 'SDInterface' object has no attribute 'GetProcesses'

import pystemd
from pystemd.systemd1 import Unit

unit = Unit(b'ssh.service') . # tried with some other units too
unit.load()
unit.Service.GetProcesses()

I am getting:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'SDInterface' object has no attribute 'GetProcesses'

Am I missing anything there?

Release .deb for ubuntu

I know we can install the pip package on ubuntu. But we have an interest in releasing a .deb package that depends on pystemd. Therefor it would be nice that this package is also released, e.g. under the name python-pystemd

So people can install using apt-get install python-pystemd instead of pip install pystemd.

Would you have an interest for this?

pystemd.run does not raise exception on collect

collect stop a pystemd.run from raising exception

In [15]: pystemd.run( 
    ...:     ['/bin/false'], 
    ...:     stdin=sys.stdin, stdout=sys.stdout,  
    ...:     wait=True, pty=True, collect=False, 
    ...:     name='mys.service', raise_on_fail=True,  
    ...: )                                                                                                          
---------------------------------------------------------------------------
PystemdRunError                           Traceback (most recent call last)
/home/aleivag/code/asg-lt/lt.py in <module>
      3     stdin=sys.stdin, stdout=sys.stdout,
      4     wait=True, pty=True, collect=False,
----> 5     name='mys.service', raise_on_fail=True,
      6 )

while

In [18]: pystemd.run( 
    ...:     ['/bin/false'], 
    ...:     stdin=sys.stdin, stdout=sys.stdout,  
    ...:     wait=True, pty=True, collect=True, 
    ...:     name='mys.service', raise_on_fail=True,  
    ...: )                                                                                                          
Out[18]: <pystemd.systemd1.unit.Unit at 0x7f703479ddd0>

In [19]:  

and both should raise exception

pip package update

The pip package (and 0.10 release in general) seems to be very out of date (last update October 2021), with the Systemd Unit "Start" function entirely missing in that old version.

Could someone possibly create a new release and bump the pip package? I can compile and install the library manually, but would still be nice to be able to do it properly via pip.

pystemd & user services

Hi,

I'm running a user service [1] defined in ~/.config/systemd/user/stub.service I'd like to manage this service via pystemd. There is no documentation for this kind of use, however I found an issue related to it where I read that pystemd should just work fine with user services.

So I tried something very simple:

bus = DBus(user_mode=True)
unit = Unit(b'stub.service', bus=bus, _autoload=True)

And I receive:

[...]
  File "/xxx/server_manager.py", line 22, in is_server_running
    unit = Unit(b'stub.service', bus=bus, _autoload=True)
  File "/xxx/lib/python3.8/site-packages/pystemd/systemd1/unit.py", line 19, in __init__
    super(Unit, self).__init__(
  File "/yyy/pyenv/versions/mc-server-manager/lib/python3.8/site-packages/pystemd/base.py", line 28, in __init__
    self.load()
  File "/yyy/pyenv/versions/mc-server-manager/lib/python3.8/site-packages/pystemd/base.py", line 89, in load
    unit_xml = self.get_introspect_xml()
  File "/yyy/pyenv/versions/mc-server-manager/lib/python3.8/site-packages/pystemd/base.py", line 75, in get_introspect_xml
    bus.call_method(
  File "pystemd/dbuslib.pyx", line 427, in pystemd.dbuslib.DBus.call_method
pystemd.dbusexc.DBusBaseError: [err -107]: Could not create DBus method
This is DBusBaseError, a base error for DBus (i bet you did not see that coming) if you need a special error, enhance pystemd.sysdexc module!.

My setup is Fedora 31, SELinux in permissive mode, cgroups v1, and this service is active:

➜  mc-server-manager git:(master) ✗ systemctl --user status stub.service
● stub.service - Stub server
     Loaded: loaded (/home/docent/.config/systemd/user/stub.service; enabled; vendor preset: disabled)
     Active: active (running) since Sat 2020-04-18 17:23:18 CEST; 7h ago
   Main PID: 457238 (sleep)
     CGroup: /user.slice/user-1000.slice/[email protected]/stub.service
             └─457238 /usr/bin/sleep 86400

[1]

[Unit]
Description=A stub service
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/sleep 86400

NoNewPrivileges=true

[Install]
WantedBy=multi-user.targe

Usage of LXML for faster performance

I'm currently trying to build a tool for managing unused socket activated services using pystemd.

However, I found that the main performance hit was the XML parser (currently xml.dom.minidom). I modified base.py to use lxml.etree.fromstring instead and the overall performance is 2.6× times better when loading properties for all '*.service units of my running system.

I know that this bring an external dependency, but would you mind considering using lxml, maybe as an optional dependency?

[Feature Request] Support user units

I would like to integrate this into my i3pystatus config to show if redshift.service is active. However this Library does not seem to allow to check user services.

Create Services/Timers

Is it possible to create services or timers with pystemd?
It would be awesome to be able to create these without having to copy files, but instead setting them up in python code.

pystemd doesn't work with Python version 3.10.1

The error:

Jan 14 09:36:06 salsal run.sh[14952]:     from pystemd.dbuslib import DBus, apply_signature
Jan 14 09:36:06 salsal run.sh[14952]: ImportError: /home/daniel/control_panel/myvenv/lib/python3.10/site-packages/pystemd/dbuslib.cpython-310-x86_64-linux-gnu.so: undefined symbol: _PyGen_Send

Versions:

$ sc --version
systemd 250 (250.2-2-arch)

$ python --version
Python 3.10.1

This is using https://aur.archlinux.org/packages/python-pystemd/, which is version 0.9.

I suspect this is due to cython/cython#3876, where Cython has issues with the latest version of Python. This was apparently fixed in 0.29.22.

I'm trying to figure out now what version of Cython we use to see if that's the issue

EnableUnitFiles fails because Interactive authentification is required

Trying to Enable unit with EnableUnitFiles fails with pystemd.dbusexc.DBusInteractiveAuthorizationRequiredError. I cannot find a way in pystemd to enable Interactive Authorization.

You can find a test case here : https://framabin.org/p/?d1d698c4f63daad7#nguiuyQ77FS4PIntbRr7RMTy5Lko/nNyAu//Z3M5Wyk=.

This functionality is implemented in other python dbus like dbus-next. And it is implemented in Perl too. You can found an example of usage in Perl here.

add the following features

update the attributes to include "TimeoutStopSec" and simpler "Exec*" family like "ExecStop" to pystemd.run

also add type to main argument of pystemd.run

allow set DinamicUser from the user setting

accepts path object, and automagically convert them o string

can you move this to `https://github.com/facebookincubator/pystemd/blob/master/pystemd/utils.py` "from pystemd.run import DynamicUser" should not work, if it works (i'm away from a real interpreter to try) its due the weird __module__ hack at the end of this file.

can you move this to https://github.com/facebookincubator/pystemd/blob/master/pystemd/utils.py "from pystemd.run import DynamicUser" should not work, if it works (i'm away from a real interpreter to try) its due the weird module hack at the end of this file.

Originally posted by @aleivag in https://github.com/facebookincubator/pystemd/pull/14/files

Memory leak in pystemd

First of all thanks for this great project.

Unfortunately we are unable to use it, since it leaks memory whenever we are accessing the ActiveState of a Unit (I haven't tested any other property yet).

Here is a minimal example to show the issue:

#!/usr/bin/env python3
from pystemd.systemd1 import Unit
import os
import psutil

if __name__ == '__main__':
    unit = Unit(b'ntpd.service')
    unit.load()
    while True:
        if unit.Unit.ActiveState == 'active':
            pass
        process = psutil.Process(os.getpid())
        print(process.memory_info().rss)

When I run this example the memory usage raises drastically. It seems to be in the C/Cython land (at least that was my conclusion after a little bit of investigation). This problem was reproduceable with different services on different machines and different flavours of Linux, as well as on python2 and python3.

Consider relicensing pystemd away from BSD+Patents

Would you guys consider relicensing pystemd away from BSD+Patents to either plain BSD-3-Clause or LGPL-2.1+ (the same license as libsystemd, which is a dependency of this)?

The BSD+Patents license is confusing and concerning for us in the ManaTools project for leveraging the module.

Import errors in examples

Both unit.py and manager.py fail with import errors.
I looks like the package has been refactored and the examples were missed.

centos7 not supported

Hello,

I just tried to install pystemd on centos 7.5.1804
but it failed because of

[root@newvirt7 ~]# pip3 install pystemd
...
pystemd/dbuslib.c:582:28: fatal error: systemd/sd-bus.h: No such file or directory

all systemd packages installed

[root@newvirt7 ~]# rpm -qa | grep -i systemd  
systemd-219-57.el7.x86_64
systemd-libs-219-57.el7.x86_64
systemd-devel-219-57.el7.x86_64
systemd-sysv-219-57.el7.x86_64

is it not supported on purpose ?
Thanks

typestubs no longer in 0.13.x

Lost editor hints for modules like dbuslib, as the .pyi files are no longer included

pystemd/systemd1/*.pyi files still appear intact, it's just pystemd/*.pyi that's missin.

str(Path(p).relative_to("pystemd")) for p in glob.glob("pystemd/**/*.pyi")

This line likely needs glob(..., recursive=True), so that ** includes the base directory and not just child directories.

I can haz asyncio API?

Some APIs like run use blocking IO which is unfortunate if pystemd is used in an asyncio-aware codebase. It would be great to be able to use pystemd without blocking the event loop or needing to work around this.

How should I start, restart, stop a service?

Hello there,

I was reading the document of this project, and, interestingly, I couldn't find any way to restart or start a service?
Any suggestions? Could you update your documents, please?

In [12]: m.Manager.EnableUnitFiles?
Signature: m.Manager.EnableUnitFiles(*args)
Docstring: <no docstring>
File:      ~/.local/lib/python3.8/site-packages/pystemd/base.py
Type:      method

This API asks for three parameters; neither name of these parameters nor the type of them is defined or documented anywhere!

Another suggestion, maybe it's better to accept a string from the user and convert it to bytes inside pystemd module.

Thanks

Unit names with @ symbol throw an Exception

Hello,

For units that have an @ symbol in their names, such as [email protected], pystemd throws an Exception. E.g:

File "pystemd/dbuslib.pyx", line 437, in pystemd.dbuslib.DBus.call_method
pystemd.dbusexc.DBusInvalidArgsError: [err -22]: Unit name [email protected] is not valid.

If we do:

from pystemd.systemd1 import Unit

u = Unit('[email protected]')
u.load()

https://github.com/facebookincubator/pystemd/blob/0.5.0/pystemd/dbuslib.pyx#L437.

Note that I'm still using version 0.5.0 since 0.6.0 has not been released yet. Would this be something that this upcoming version would address or am I missing something?

How to enable/disable units?

I cannot find any example on how to enable/disable units. Can someone elaborate on how this can be done using this lib?
I can see there is a function called EnableUnitFiles but I am not sure how it should be used!

Can't enable/disable services: DBusBaseError: [err -42]: Unknown arg type 255 for None

Hi!
I had a script which worked perfectly to enable/disable start/stop some services. Since an OS clean reinstallation (same armbian buster), it doesn't work anymore, and I really don't understand why. Here is my test:

In [10] from pystemd.systemd1 import Manager
In [11] manager = Manager(_autoload=True)
In [12]: manager.Manager.GetUnitFileState(b'str2str_tcp.service')
Out[12]: b'disabled'
In [13]: manager.Manager.EnableUnitFiles([b'str2str_tcp.service'], False, True)
---------------------------------------------------------------------------
DBusBaseError                             Traceback (most recent call last)
<ipython-input-13-e636eb23f4dc> in <module>
----> 1 manager.Manager.EnableUnitFiles([b'str2str_tcp.service'], False, True)

/usr/local/lib/python3.7/dist-packages/pystemd/base.py in _call(self, *args)
    189 def _wrap_call_with_name(func, name):
    190     def _call(self, *args):
--> 191         return func(self, name, *args)
    192
    193     return _call

/usr/local/lib/python3.7/dist-packages/pystemd/base.py in _call_method(self, method_name, *args)
    159         ]
    160
--> 161         return self._auto_call_dbus_method(method_name, in_args, *args)
    162
    163     def _auto_call_dbus_method(self, method_name, in_args, *args):

/usr/local/lib/python3.7/dist-packages/pystemd/base.py in _auto_call_dbus_method(self, method_name, in_args, *args)
    183                 self.interface_name,
    184                 x2char_star(method_name),
--> 185                 call_args,
    186             ).body
    187

pystemd/dbuslib.pyx in pystemd.dbuslib.DBus.call_method()

pystemd/dbuslib.pyx in pystemd.dbuslib.DBus._msg_append()

DBusBaseError: [err -42]: Unknown arg type 255 for None
This is DBusBaseError, a base error for DBus (i bet you did not see that coming) if you need a special error, enhance pystemd.sysdexc module!.

SBC: Orange pi Zero with armbian buster
Python: v3.7.3
pystemd: v0.7.0
libsystemd-dev: 241-7~deb10u3

I have the same code working correctly inside various VM (Ubuntu 18, 20, Debian Buster, ...) and I know another user with the same problem on a Raspberry with Raspbian buster lite.

I've tested after installing pystemd from this repo with the same result.

I've tested with systemd-manager and it works.

Could somebody help me?

is there any way to get better error messages from dbuslib.call_method?

Trying to follow the example for starting a transient unit from here: https://github.com/facebookincubator/pystemd/blob/master/examples/start_transient_unit.py

        manager.Manager.StartTransientUnit(
            procname, b'fail',
            {
                b'Description': b'Carbonite Crawl %s on %s' % (name, target),
                b'ExecStart': [(cmd[0], cmd, False)],
                b'RemainAfterExit': True
            })

However, I'm getting the following error:

pystemd/dbuslib.pyx in pystemd.dbuslib.DBus.call_method()

TypeError: expected bytes, int found

> /home/fedora/carbonite/pystemd/dbuslib.pyx(389)pystemd.dbuslib.DBus.call_method()

Because it is cython, I don't know how far the loop got.

I can see the args getting passed in to call_method:

ipdb> args
self = <pystemd.systemd1.manager.Manager object at 0x7f0fd922f160>
interface_name = b'org.freedesktop.systemd1.Manager'
name = b'carbonite.crawl-test-auto-crawl.service'
smode = b'fail'
properties = {b'Description': b'Carbonite Crawl test-auto-crawl on ec2-52-26-199-38.us-west-2.compute.amazonaws.com', b'ExecStart': [(115, b'scrapy crawl sl_spider -a session_name=test-auto-crawl -a usernames=email-1024 -a password=wrong-password -a target=https://ec2-52-26-199-38.us-west-2.compute.amazonaws.com\n', False)], b'RemainAfterExit': True}
extra_units = None

I think putting the value and/or name of the argument causing the problem would improve debugability a lot.

EDIT: the bug was I forgot to split the byte-string into a list, so cmd[0] was returning an integer

sd_bus_match_symbol requires systemd >=237

pystemd version 0.6.0 references sd_bus_match_signal, which only exists in systemd >=237. Users on older OSes (e.g. Ubuntu Xenial) will experience an error importing pystemd, like so:

$ python 
Python 3.7.2 (default, Dec 25 2018, 22:05:20) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pystemd import systemd1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/nfsuper/env/lib/python3.7/site-packages/pystemd/__init__.py", line 103, in <module>
    from pystemd import DBus, __version__, machine1, systemd1
  File "/home/nfsuper/env/lib/python3.7/site-packages/pystemd/DBus/__init__.py", line 10, in <module>
    from pystemd.base import SDObject
  File "/home/nfsuper/env/lib/python3.7/site-packages/pystemd/base.py", line 14, in <module>
    from pystemd.dbuslib import DBus, apply_signature
ImportError: /home/nfsuper/env/lib/python3.7/site-packages/pystemd/dbuslib.cpython-37m-x86_64-linux-gnu.so: undefined symbol: sd_bus_match_signal 

Possible solutions include a) document the required systemd version or b) disable the feature when compiled against versions not including the necessary symbols.

Install process fails

Following the read me and running

pip install -r requirements.txt
python setup.py install

The install fails with the use of Path objects in package_data:

(.venv) mav@dev:~/code/pystemd-testing/pystemd$ python3 setup.py install
Compiling pystemd/daemon.pyx because it changed.
Compiling pystemd/dbusexc.pyx because it changed.
Compiling pystemd/dbuslib.pyx because it changed.
Compiling pystemd/journal.pyx because it changed.
[1/4] Cythonizing pystemd/daemon.pyx
[2/4] Cythonizing pystemd/dbusexc.pyx
[3/4] Cythonizing pystemd/dbuslib.pyx
[4/4] Cythonizing pystemd/journal.pyx
error in pystemd setup command: "values of 'package_data' dict" must be a list of strings (got [PosixPath('RELEASE'), PosixPath('daemon.pyi'), PosixPath('utils.pyi'), PosixPath('base.pyi'), PosixPath('systemd1/manager.pyi'), PosixPath('systemd1/unit.pyi')])

edit: updated to remove the cython requirement "fix"... that is clearly covered in the read me.

Enable command?

Hello, I dug through the code and couldn't find an enable command. Is there an ability to enable a service so it comes up on reboot? This is specifically for Instantiated Services. Thank you for this module!

Psystemd not working properly with PyInstaller

In my project I needed a way to handle systemctl signals gracefully so I decided to use psystemd. Other alternatives did not perform properly. My main goal is to convert my Python script to executable and make it run as a service in the backgorund. The main problem I am facing rn is that my code cannot process systemctl stop signal gracefully. The way I implemented psystemd is given below.

from pystemd.systemd1 import Unit

if __name__ == "__main__":
    try:
        myc = Dlp_Service()
        myc.start()
        while True:
            sleep(1)

            if myc.unit.Unit.ActiveState == b"deactivating":
                myc.stop()
    except Exception as e:
        print(e)
        myc.stop()

It is initiated inside the Dlp_Service constructor like self.unit = Unit(b"myservice.service").
The error message is "ModuleNotFoundError: No module named 'pystemd.dbusexc'". The executable is created inside a virtual environment that has psystemd installed and this program works flawless as a Python script. How can i handle this error and use my program as executable?

Service.MainPID is zero

hi

i am trying to create simple monitor of icecast service,
is there reason why pystemd is returning Service.MainPID always 0 ?

In [2]: unit = Unit("icecast2.service", _autoload=True)
In [3]: unit.Service.MainPID
Out[3]: 0
systemctl status icecast2.service 
● icecast2.service - LSB: Icecast2 streaming media server
     Loaded: loaded (/etc/init.d/icecast2; generated)
     Active: active (running) since Sun 2024-04-14 20:46:21 UTC; 44min ago
       Docs: man:systemd-sysv-generator(8)
    Process: 2091674 ExecStart=/etc/init.d/icecast2 start (code=exited, status=0/SUCCESS)

real PID:

pidof icecast2
2091678

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.