A systemd binding Library in Python
Project description
PySystemd
PySystemd is a Python library for managing and interacting with system services using systemd
. This library provides functionality to check the status of services, manage service states, list services, manage power operations, and retrieve system status information.
Features
- ServiceStatus: Check if a service is running or enabled, and retrieve detailed status information.
- ServiceManager: Start, stop, restart, reload, enable, and disable services.
- ServiceLister: List all services, running services, not running services, enabled services, and disabled services.
- PowerManager: Perform power operations like power off, reboot, rescue, and suspend.
- SystemStatus: Get system uptime and load average.
Installation
pip install pysystemd
or simply clone this repository and import the required classes into your project.
Usage
Checking Service Status
from pysystemd import ServiceStatus
service = ServiceStatus('apache2')
print(service.is_running()) # Check if the service is running
print(service.is_enabled()) # Check if the service is enabled
print(service.get_status()) # Get detailed status of the service
### Managing Services
```python
from pysystemd import ServiceManager
manager = ServiceManager('apache2')
manager.start() # Start the service
manager.stop() # Stop the service
manager.restart() # Restart the service
manager.reload() # Reload the service
manager.enable() # Enable the service
manager.disable() # Disable the service
Listing Services
from pysystemd import ServiceLister
print(ServiceLister.list_all()) # List all services
print(ServiceLister.list_running()) # List all running services
print(ServiceLister.list_not_running()) # List all not running services
print(ServiceLister.list_enabled()) # List all enabled services
print(ServiceLister.list_disabled()) # List all disabled services
Power Management
from pysystemd import PowerManager
PowerManager.poweroff() # Power off the system
PowerManager.reboot() # Reboot the system
PowerManager.rescue() # Boot to rescue mode
PowerManager.suspend() # Suspend the system
System Status
from pysystemd import SystemStatus
print(SystemStatus.uptime()) # Get system uptime
print(SystemStatus.load_average()) # Get system load average
Logging
PySystemd uses Python's built-in logging
module to provide detailed logs of its operations. By default, the logging level is set to INFO
and the format includes the timestamp, log level, and message.
Contributing
Contributions are welcome! Please fork the repository and submit pull requests for any features, bug fixes, or improvements.
License
This project is licensed under the LGPL v3 License.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file pysystemd-1.1.tar.gz
.
File metadata
- Download URL: pysystemd-1.1.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6713014b1d0ccdda42136516957d3e015615b4693aafe491f470fc28c06afab0 |
|
MD5 | 38f687fe2ff7918e8cdc9c36ea520db5 |
|
BLAKE2b-256 | 06e01163b05b669c68cc95c6d9fcbdc904f1fdc5df3dc831dc9b59c6676ad5d6 |