- Notifications
You must be signed in to change notification settings - Fork1
Programmatically create systemd unit files and manage them
License
NotificationsYou must be signed in to change notification settings
t4d-gmbh/systemdunits
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Small package for reading and writing systemd unit files.
Fetch the latest version directly from the repository:
pip install --upgrade git+https://github.com/tools4digits/systemdunits.git
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()
Testing is done withunittest
, includingdoctest
.
To run tests simply go to the project root folder and run:
python -m unittest
Copyright © 2022 T4D GmbH
About
Programmatically create systemd unit files and manage them
Topics
Resources
License
Stars
Watchers
Forks
Packages0
No packages published