{ "info": { "author": "Alvaro Leiva", "author_email": "aleivag@fb.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "Intended Audience :: System Administrators", "License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Utilities" ], "description": "pystemd\n=======\n\n[![Build Status](https://travis-ci.org/facebookincubator/pystemd.svg)](http://travis-ci.org/facebookincubator/pystemd) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)\n\nThis library allows you to talk to systemd over dbus from python, without\nactually thinking that you are talking to systemd over dbus. This allows you to\nprogrammatically start/stop/restart/kill and verify services status from\nsystemd point of view, avoiding executing `subprocess.Popen(['systemctl', ...`\nand then parsing the output to know the result.\n\n\nShow don't tell\n---------------\n\nIn software as in screenwriting, its better to show how things work instead of\ntell. So this is how you would use the library from a interactive shell. \n\n In [1]: from pystemd.systemd1 import Unit\n In [2]: unit = Unit(b'postfix.service')\n In [3]: unit.load()\n\nNote: you need to call `unit.load()` because by default `Unit` will not load the\nunit information as that would require do some IO. You can auto load the unit by\n`Unit(b'postfix.service', _autoload=True)`\n\nOnce the unit is loaded, you can interact with it, you can do by accessing its\nsystemd's interfaces:\n\n In [4]: unit.Unit.ActiveState\n Out[4]: b'active'\n\n In [5]: unit.Unit.StopWhenUnneeded\n Out[5]: False\n\n In [6]: unit.Unit.Stop(b'replace') # require privilege account\n Out[6]: b'/org/freedesktop/systemd1/job/6601531'\n\n In [7]: unit.Unit.ActiveState\n Out[7]: b'inactive'\n\n In [8]: unit.Unit.Start(b'replace') # require privilege account\n Out[8]: b'/org/freedesktop/systemd1/job/6601532'\n\n In [9]: unit.Unit.ActiveState\n Out[9]: b'active'\n\n In [10]: unit.Service.GetProcesses()\n Out[10]:\n [(b'/system.slice/postfix.service',\n 1754222,\n b'/usr/libexec/postfix/master -w'),\n (b'/system.slice/postfix.service', 1754224, b'pickup -l -t fifo -u'),\n (b'/system.slice/postfix.service', 1754225, b'qmgr -l -t fifo -u')]\n\n In [11]: unit.Service.MainPID\n Out[11]: 1754222\n\nThe `systemd1.Unit` class provides shortcuts for the interfaces in the systemd\nnamespace, as you se above, we have Service (org.freedesktop.systemd1.Service)\nand Unit (org.freedesktop.systemd1.Unit). Others can be found in\n`unit._interfaces` as:\n\n```\nIn [12]: unit._interfaces\nOut[12]:\n{'org.freedesktop.DBus.Introspectable': ,\n 'org.freedesktop.DBus.Peer': ,\n 'org.freedesktop.DBus.Properties': ,\n 'org.freedesktop.systemd1.Service': ,\n 'org.freedesktop.systemd1.Unit': }\n\n In [13]: unit.Service\n Out[13]: \n```\n\nEach interface has methods and properties, that can access directly as\n`unit.Service.MainPID`, the list of properties and methods is in `.properties`\nand `.methods` of each interface.\n\nAlongside the `systemd1.Unit`, we also have a `systemd1.Manager`, that allows\nyou to interact with systemd manager.\n\n\n```\nIn [14]: from pystemd.systemd1 import Manager\n\nIn [15]: manager = Manager()\n\nIn [16]: manager.load()\n\nIn [17]: manager.Manager.ListUnitFiles()\nOut[17]:\n...\n(b'/usr/lib/systemd/system/rhel-domainname.service', b'disabled'),\n (b'/usr/lib/systemd/system/fstrim.timer', b'disabled'),\n (b'/usr/lib/systemd/system/getty.target', b'static'),\n (b'/usr/lib/systemd/system/systemd-user-sessions.service', b'static'),\n...\n\nIn [18]: manager.Manager.Architecture\nOut[18]: b'x86-64'\n\nIn [19]: manager.Manager.Virtualization\nOut[19]: b'kvm'\n\n```\n\nExtras:\n-------\nWe also include `pystemd.run`, the spiritual port of systemd-run\nto python. [example of usage](_docs/pystemd.run.md):\n\n```python\n# run this as root\n>>> import pystemd.run, sys\n>>> pystemd.run(\n [b'/usr/bin/psql', b'postgres'],\n machine=b'db1',\n user=b'postgres',\n wait=True,\n pty=True,\n stdin=sys.stdin, stdout=sys.stdout,\n env={b'PGTZ': b'UTC'}\n)\n```\n\nwill open a postgres interactive prompt in a local nspawn-machine.\n\nYou also get an interface to `sd_notify` in the form of `pystemd.daemon.notify` [docs](_docs/daemon.md).\n\n```python\n# run this as root\n>>> import pystemd.daemon\n>>> pystemd.daemon.notify(False, ready=1, status='Gimme! Gimme! Gimme!')\n```\n\nAnd access to listen file descriptors for socket activation scripts.\n\n```python\n# run this as root\n>>> import pystemd.daemon\n>>> pystemd.daemon.LISTEN_FDS_START\n3\n>>> pystemd.daemon.listen_fds()\n1 # you normally only open 1 socket\n```\n\nAnd access if watchdog is enabled and ping it.\n\n```python\nimport time\nimport pystemd.daemon\n\nwatchdog_usec = pystemd.daemon.watchdog_enabled()\nwatchdog_sec = watchdog_usec/10**6\n\nif not watchdog_usec:\n print(f'watchdog was not enabled!')\n\nfor i in range(20):\n pystemd.daemon.notify(False, watchdog=1, status=f'count {i+1}')\n time.sleep(watchdog_sec*0.5)\n\nprint('sleeping for 30 seconds')\ntime.sleep(watchdog_sec*2)\nprint('you will never reach me in a watchdog env')\n\n```\n\nInstall\n-------\n\nSo you like what you see, the simplest way to install is by:\n\n```bash\n$ pip install pystemd\n```\n\nyou'll need to have:\n\n* Python headers: Just use your distro's package (e.g. python-dev).\n* systemd headers: Chances are you already have this. Normally, it is called\n`libsystemd-dev` or `systemd-devel`. You need to have at least v221.\nPlease note that CentOS 7 ships with version 219. To work around this, please read\n [this](_docs/centos7.md).\n* systemd library: check if `pkg-config --cflags --libs libsystemd` returns\n`-lsystemd` if not you can install normally install `systemd-libs` or\n`libsystemd` depending on your distribution, version needs to be at least\nv221.\n* gcc: or any compiler that `setup.py` will accept.\n\nif you want to install from source then after you clone this repo you need to\n\n```bash\n$ pip install -r requirements.txt # get six\n$ python3 setup.py install # only python3 supported\n```\n\nbut in addition to previous requirements you'll need:\n\n * setuptools: Just use your distro's package (e.g. python-setuptools).\n * Six library: for python 2 and 3 compatibility (installed by requirements).\n * Cython: at least version 0.21a1, just pip install it or use the official\n installation guide from cython homepage to get latest\n http://cython.readthedocs.io/en/latest/src/quickstart/install.html.\n\n\nLearning more\n-------------\n\nThis project has been covered in a number of conference talks:\n* [Using systemd in high level languages](https://www.youtube.com/watch?v=lBQgMGPxqNo) at [All Systems Go! 2018](https://all-systems-go.io)\n* [systemd: why you should care as a Python developer](https://www.youtube.com/watch?v=ZUX9Fx8Rwzg) at [PyCon 2018](https://us.pycon.org/2018/)\n* [Better security for Python with systemd](https://www.youtube.com/watch?v=o-OqslA5dkw) at [Pyninsula #10](https://www.meetup.com/Pyninsula-Python-Peninsula-Meetup/events/244939632/)\n\nA [Vagrant-based demo](https://github.com/aleivag/pycon2018) was also developed\nfor PyCon 2018.\n\nLicense\n-------\n\npystemd is licensed under LGPL 2.1 or later.", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/facebookincubator/pystemd", "keywords": "systemd", "license": "LGPL-2.1+", "maintainer": "", "maintainer_email": "", "name": "pystemd", "package_url": "https://pypi.org/project/pystemd/", "platform": "", "project_url": "https://pypi.org/project/pystemd/", "project_urls": { "Homepage": "https://github.com/facebookincubator/pystemd" }, "release_url": "https://pypi.org/project/pystemd/0.6.0/", "requires_dist": null, "requires_python": "", "summary": "A systemd binding for python", "version": "0.6.0" }, "last_serial": 4942404, "releases": { "0.2.0": [ { "comment_text": "", "digests": { "md5": "9bfd01f4fb4831cff95762df64bbb56e", "sha256": "6961fce3bdb4b6bcddcb12b42d81579f5ca2e3f3ffb758685c36577b81bf9f5b" }, "downloads": -1, "filename": "pystemd-0.2.0.tar.gz", "has_sig": false, "md5_digest": "9bfd01f4fb4831cff95762df64bbb56e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 138568, "upload_time": "2018-01-12T01:38:59", "url": "https://files.pythonhosted.org/packages/44/cd/7a204ed3877e97358ab50942c113d1b4839b088717ccac6a962d97c10ed1/pystemd-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "f0db419fd8d0eda686c52516d0e80368", "sha256": "684664c968eb87b2533f7a7599f3d5ae7ed4f384cbaff24e4bf8eef853432798" }, "downloads": -1, "filename": "pystemd-0.3.0.tar.gz", "has_sig": false, "md5_digest": "f0db419fd8d0eda686c52516d0e80368", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 135524, "upload_time": "2018-02-02T21:41:22", "url": "https://files.pythonhosted.org/packages/32/d2/d7b2e4f6b6d6051d7331d094034d0451c50bd7d1ffef90b5d52cd9517c44/pystemd-0.3.0.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "3f1547b3c76f8e378db09f4c2bd6e30a", "sha256": "7639e3fcdf6a8f83ef5f10bcb3613880c28e4e451323b221697eafd6b74ec5c2" }, "downloads": -1, "filename": "pystemd-0.4.0.tar.gz", "has_sig": false, "md5_digest": "3f1547b3c76f8e378db09f4c2bd6e30a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 191380, "upload_time": "2018-03-29T17:53:16", "url": "https://files.pythonhosted.org/packages/d5/60/3ce323314a2a239a38d782801315a708c64516159070cdb528deb458243a/pystemd-0.4.0.tar.gz" } ], "0.5.0": [ { "comment_text": "", "digests": { "md5": "272f9aec7f1a3fc47c2a04191b0e0b22", "sha256": "251a14d26235df1408cacdf0db24c38725b405795b01b635e3bb88dd61000000" }, "downloads": -1, "filename": "pystemd-0.5.0.tar.gz", "has_sig": false, "md5_digest": "272f9aec7f1a3fc47c2a04191b0e0b22", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 193009, "upload_time": "2018-06-08T23:21:15", "url": "https://files.pythonhosted.org/packages/1a/3c/71f037abb980a9ec4bfea344bb4aa161109f8121a67a5940f663dd723791/pystemd-0.5.0.tar.gz" } ], "0.6.0": [ { "comment_text": "", "digests": { "md5": "c5472be419f53f53f5da089ca8c981c0", "sha256": "b1fc072c87e3766711f64caf86fd633dca393e20c8a0a37a5058dd70a21d8a14" }, "downloads": -1, "filename": "pystemd-0.6.0.tar.gz", "has_sig": false, "md5_digest": "c5472be419f53f53f5da089ca8c981c0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 213572, "upload_time": "2019-03-15T02:37:06", "url": "https://files.pythonhosted.org/packages/aa/b6/b0b87515c933801122f2ad01366692a492c751e3525a4af5e1ecbe59aa17/pystemd-0.6.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c5472be419f53f53f5da089ca8c981c0", "sha256": "b1fc072c87e3766711f64caf86fd633dca393e20c8a0a37a5058dd70a21d8a14" }, "downloads": -1, "filename": "pystemd-0.6.0.tar.gz", "has_sig": false, "md5_digest": "c5472be419f53f53f5da089ca8c981c0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 213572, "upload_time": "2019-03-15T02:37:06", "url": "https://files.pythonhosted.org/packages/aa/b6/b0b87515c933801122f2ad01366692a492c751e3525a4af5e1ecbe59aa17/pystemd-0.6.0.tar.gz" } ] }