Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Programmatically create systemd unit files and manage them

License

NotificationsYou must be signed in to change notification settings

t4d-gmbh/systemdunits

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Small package for reading and writing systemd unit files.

Installation

Fetch the latest version directly from the repository:

pip install --upgrade git+https://github.com/tools4digits/systemdunits.git

Usage Examples

Creating systemd units

Create a new target unit template using the default manager (i.e.--user),write it to~/.config/systemd/user, start an instance, show the status,stop it again and clean up:

importasynciofromsysunitimportSystemUnitmy_target=SystemUnit('test-example@.target')# some dummy contentmy_target.from_dict(dict(Unit=dict(Description='Target instance %i'),Install=dict(WantedBy='multi-user.target')))# write it to diskmy_target.write()# reload the systmd daemon (this is an async operation)asyncio.run(my_target.run.daemon_reload())# start an instance of this unitasyncio.run(my_target.run.start(instance='eg1'))# get the statusout,err=asyncio.run(my_target.run.status(instance='eg1'))print(out)# ● test-example@eg1.target - Target instance eg1#  Loaded: loaded (.../.config/systemd/user/test-example@.target; disabled;#          vendor preset: enabled)#  Active: active since ... ago#  ... systemd[...]: Reached target Target instance eg1.# stop the instance againasyncio.run(my_target.run.stop(instance='eg1'))# remove the unit file againmy_target.remove()

Development

Testing

Testing is done withunittest, includingdoctest.

To run tests simply go to the project root folder and run:

python -m unittest

Copyright

Copyright © 2022 T4D GmbH

About

Programmatically create systemd unit files and manage them

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp