# service_config_foundry
**service_config_foundry** is a Python-based library that simplifies the process of creating, updating, replacing, and deleting systemd service files for Linux users. With this tool, you can easily manage systemd services programmatically, reducing the complexity of writing and maintaining service configuration files manually.
## Features
- Create and manage non-templated systemd service files
- Support for various systemd file types including `.service`, `.timer`, `.socket`, `.mount`, and more
- Programmatic control over file attributes and configurations
- Replace and update existing services without conflicts
- Fully integrated Python API with no external dependencies
## Installation
You can install the library using `pip`:
```bash
pip install service_config_foundry
```
Or you can install the library using `pip` directly from the GitHub repository:
```bash
pip install git+https://github.com/yushdotkapoor/service_config_foundry.git
```
Alternatively, clone the repository to get started:
```bash
git clone https://github.com/yushdotkapoor/service_config_foundry.git
cd service_config_foundry
```
## Usage
Below are detailed examples of how to use `service_config_foundry` to create and manage systemd files of various types.
### Example: Creating a Service, Timer, and Socket
```python
from service_config_foundry import Service, ServiceLocation
# Create a new service instance
service = Service("example", service_location=ServiceLocation.GLOBAL, auto_start=False, enable_at_startup=False, force_overwrite=False)
# Configure the service file
service_file = service.service_file
service_file.unit.description = "Example service for demonstration purposes"
service_file.service.user = "yushrajkapoor"
service_file.service.exec_start = "echo Hello, world >> /tmp/example.log"
service_file.install.wanted_by = "multi-user.target"
# Configure the timer file
timer_file = service.timer_file
timer_file.unit.description = "Example timer for demonstration purposes"
timer_file.timer.on_calendar = "*-*-* *:00:00"
timer_file.install.wanted_by = "timers.target"
# Configure the socket file
socket_file = service.socket_file
socket_file.unit.description = "Example socket for demonstration purposes"
socket_file.socket.listen_stream = "/run/example.sock"
socket_file.install.wanted_by = "sockets.target"
# Create or update the service, timer, and socket files
service.update()
# Enable the service to start at boot time
service.enable_service_at_startup()
# Start the service
service.start_service()
# Display the status of the service
service.status()
```
### Output Files
#### `example.service`
```ini
[Unit]
Description=Example service for demonstration purposes
[Service]
User=yushrajkapoor
ExecStart=echo Hello, world >> /tmp/example.log
[Install]
WantedBy=multi-user.target
```
#### `example.timer`
```ini
[Unit]
Description=Example timer for demonstration purposes
[Timer]
OnCalendar=*-*-* *:00:00
[Install]
WantedBy=timers.target
```
#### `example.socket`
```ini
[Unit]
Description=Example socket for demonstration purposes
[Socket]
ListenStream=/run/example.sock
[Install]
WantedBy=sockets.target
```
### Example: Replacing an Existing Service
If you want to replace an existing service configuration, you can use the `replace()` method. This ensures that any old files are removed and replaced with the new configuration.
```python
# Replace the existing service configuration
service.replace()
```
This is particularly useful when you want to ensure that your updates overwrite any conflicting configurations from previous versions of the service.
### Example: Creating Mount and Automount Files
```python
# Configure the mount file
mount_file = service.mount_file
mount_file.unit.description = "Example mount for demonstration purposes"
mount_file.mount.what = "/dev/sda1"
mount_file.mount.where = "/mnt/example"
mount_file.mount.type = "ext4"
mount_file.install.wanted_by = "multi-user.target"
# Configure the automount file
automount_file = service.automount_file
automount_file.unit.description = "Example automount for demonstration purposes"
automount_file.automount.where = "/mnt/example"
automount_file.install.wanted_by = "multi-user.target"
# Create or update the files
service.update()
```
#### `example.mount`
```ini
[Unit]
Description=Example mount for demonstration purposes
[Mount]
What=/dev/sda1
Where=/mnt/example
Type=ext4
[Install]
WantedBy=multi-user.target
```
#### `example.automount`
```ini
[Unit]
Description=Example automount for demonstration purposes
[Automount]
Where=/mnt/example
[Install]
WantedBy=multi-user.target
```
### Example: Creating Swap and Path Files
```python
# Configure the swap file
swap_file = service.swap_file
swap_file.unit.description = "Example swap for demonstration purposes"
swap_file.swap.what = "/swapfile"
swap_file.install.wanted_by = "multi-user.target"
# Configure the path file
path_file = service.path_file
path_file.unit.description = "Example path for demonstration purposes"
path_file.path.path_exists = "/tmp/example"
path_file.install.wanted_by = "multi-user.target"
# Create or update the files
service.update()
```
#### `example.swap`
```ini
[Unit]
Description=Example swap for demonstration purposes
[Swap]
What=/swapfile
[Install]
WantedBy=multi-user.target
```
#### `example.path`
```ini
[Unit]
Description=Example path for demonstration purposes
[Path]
PathExists=/tmp/example
[Install]
WantedBy=multi-user.target
```
### Example: Creating Slice and Scope Files
```python
# Configure the slice file
slice_file = service.slice_file
slice_file.unit.description = "Example slice for demonstration purposes"
# Configure the scope file
scope_file = service.scope_file
scope_file.unit.description = "Example scope for demonstration purposes"
scope_file.scope.slice = "example.slice"
# Create or update the files
service.update()
```
#### `example.slice`
```ini
[Unit]
Description=Example slice for demonstration purposes
```
#### `example.scope`
```ini
[Unit]
Description=Example scope for demonstration purposes
[Scope]
Slice=example.slice
```
### Deleting a Service
To delete a service and its associated files:
```python
service.delete()
```
This will remove all files matching the service name in the systemd directory.
## Configuration Options
`service_config_foundry` supports multiple systemd file types, including:
- `.service` - Main service configuration
- `.socket` - Socket configuration
- `.timer` - Timer configuration
- `.mount` - Mount point configuration
- `.automount` - Automount configuration
- `.swap` - Swap space configuration
- `.path` - Path configuration
- `.slice` - Slice configuration
- `.scope` - Scope configuration
## Development
### Running Tests
This project includes comprehensive test coverage using pytest. To run the tests:
```bash
# Install test dependencies
pip install -e ".[test]"
# Run all tests
pytest tests/
# Run tests with coverage
pytest tests/ --cov=service_config_foundry --cov-report=term-missing
# Run tests with coverage report in HTML
pytest tests/ --cov=service_config_foundry --cov-report=html
```
### Development Setup
For development, install the package in development mode with all dependencies:
```bash
# Install development dependencies
pip install -e ".[dev]"
# Install pre-commit hooks
pre-commit install
# Run pre-commit on all files
pre-commit run --all-files
```
### Using Make Commands
The project includes a Makefile for common development tasks:
```bash
# Install for development
make dev-install
# Run tests
make test
# Run tests with coverage
make test-cov
# Format code
make format
# Run linting
make lint
# Clean build artifacts
make clean
```
### GitHub Actions
The project includes GitHub Actions workflows that:
- Run tests on every push and pull request
- Test against multiple Python versions (3.8-3.12)
- Check code formatting and linting
- Generate coverage reports
- Automatically publish to PyPI on tagged releases
## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
## Contributing
Contributions are welcome! If you encounter any issues or have suggestions for improvement, please open an issue or submit a pull request.
Before contributing:
1. Fork the repository
2. Create a feature branch
3. Make your changes with appropriate tests
4. Ensure all tests pass
5. Submit a pull request
## Contact
- **Author**: Yush Kapoor
- **Email**: [yushdotkapoor@gmail.com](mailto:yushdotkapoor@gmail.com)
- **GitHub**: [https://github.com/yushdotkapoor/service_config_foundry](https://github.com/yushdotkapoor/service_config_foundry)
## Acknowledgments
Special thanks to the Linux and Python communities for their inspiration and support in creating this project.
Raw data
{
"_id": null,
"home_page": "https://github.com/yushdotkapoor/service-config-foundry",
"name": "service-config-foundry",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "systemd, service, linux, system-administration",
"author": "Yush Kapoor",
"author_email": "Yush Kapoor <yushdotkapoor@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/85/f7/c12815f4eadbe837574f06dc53928c22a9d33f11868febc594038b625c8c/service_config_foundry-0.5.5.tar.gz",
"platform": null,
"description": "# service_config_foundry\n\n**service_config_foundry** is a Python-based library that simplifies the process of creating, updating, replacing, and deleting systemd service files for Linux users. With this tool, you can easily manage systemd services programmatically, reducing the complexity of writing and maintaining service configuration files manually.\n\n## Features\n\n- Create and manage non-templated systemd service files\n- Support for various systemd file types including `.service`, `.timer`, `.socket`, `.mount`, and more\n- Programmatic control over file attributes and configurations\n- Replace and update existing services without conflicts\n- Fully integrated Python API with no external dependencies\n\n## Installation\nYou can install the library using `pip`:\n```bash\npip install service_config_foundry\n```\n\nOr you can install the library using `pip` directly from the GitHub repository:\n\n```bash\npip install git+https://github.com/yushdotkapoor/service_config_foundry.git\n```\n\nAlternatively, clone the repository to get started:\n\n```bash\ngit clone https://github.com/yushdotkapoor/service_config_foundry.git\ncd service_config_foundry\n```\n\n## Usage\n\nBelow are detailed examples of how to use `service_config_foundry` to create and manage systemd files of various types.\n\n### Example: Creating a Service, Timer, and Socket\n\n```python\nfrom service_config_foundry import Service, ServiceLocation\n\n# Create a new service instance\nservice = Service(\"example\", service_location=ServiceLocation.GLOBAL, auto_start=False, enable_at_startup=False, force_overwrite=False)\n\n# Configure the service file\nservice_file = service.service_file\nservice_file.unit.description = \"Example service for demonstration purposes\"\nservice_file.service.user = \"yushrajkapoor\"\nservice_file.service.exec_start = \"echo Hello, world >> /tmp/example.log\"\nservice_file.install.wanted_by = \"multi-user.target\"\n\n# Configure the timer file\ntimer_file = service.timer_file\ntimer_file.unit.description = \"Example timer for demonstration purposes\"\ntimer_file.timer.on_calendar = \"*-*-* *:00:00\"\ntimer_file.install.wanted_by = \"timers.target\"\n\n# Configure the socket file\nsocket_file = service.socket_file\nsocket_file.unit.description = \"Example socket for demonstration purposes\"\nsocket_file.socket.listen_stream = \"/run/example.sock\"\nsocket_file.install.wanted_by = \"sockets.target\"\n\n# Create or update the service, timer, and socket files\nservice.update()\n\n# Enable the service to start at boot time\nservice.enable_service_at_startup()\n\n# Start the service\nservice.start_service()\n\n# Display the status of the service\nservice.status()\n```\n\n### Output Files\n\n#### `example.service`\n```ini\n[Unit]\nDescription=Example service for demonstration purposes\n\n[Service]\nUser=yushrajkapoor\nExecStart=echo Hello, world >> /tmp/example.log\n\n[Install]\nWantedBy=multi-user.target\n```\n\n#### `example.timer`\n```ini\n[Unit]\nDescription=Example timer for demonstration purposes\n\n[Timer]\nOnCalendar=*-*-* *:00:00\n\n[Install]\nWantedBy=timers.target\n```\n\n#### `example.socket`\n```ini\n[Unit]\nDescription=Example socket for demonstration purposes\n\n[Socket]\nListenStream=/run/example.sock\n\n[Install]\nWantedBy=sockets.target\n```\n\n### Example: Replacing an Existing Service\n\nIf you want to replace an existing service configuration, you can use the `replace()` method. This ensures that any old files are removed and replaced with the new configuration.\n\n```python\n# Replace the existing service configuration\nservice.replace()\n```\n\nThis is particularly useful when you want to ensure that your updates overwrite any conflicting configurations from previous versions of the service.\n\n### Example: Creating Mount and Automount Files\n\n```python\n# Configure the mount file\nmount_file = service.mount_file\nmount_file.unit.description = \"Example mount for demonstration purposes\"\nmount_file.mount.what = \"/dev/sda1\"\nmount_file.mount.where = \"/mnt/example\"\nmount_file.mount.type = \"ext4\"\nmount_file.install.wanted_by = \"multi-user.target\"\n\n# Configure the automount file\nautomount_file = service.automount_file\nautomount_file.unit.description = \"Example automount for demonstration purposes\"\nautomount_file.automount.where = \"/mnt/example\"\nautomount_file.install.wanted_by = \"multi-user.target\"\n\n# Create or update the files\nservice.update()\n```\n\n#### `example.mount`\n```ini\n[Unit]\nDescription=Example mount for demonstration purposes\n\n[Mount]\nWhat=/dev/sda1\nWhere=/mnt/example\nType=ext4\n\n[Install]\nWantedBy=multi-user.target\n```\n\n#### `example.automount`\n```ini\n[Unit]\nDescription=Example automount for demonstration purposes\n\n[Automount]\nWhere=/mnt/example\n\n[Install]\nWantedBy=multi-user.target\n```\n\n### Example: Creating Swap and Path Files\n\n```python\n# Configure the swap file\nswap_file = service.swap_file\nswap_file.unit.description = \"Example swap for demonstration purposes\"\nswap_file.swap.what = \"/swapfile\"\nswap_file.install.wanted_by = \"multi-user.target\"\n\n# Configure the path file\npath_file = service.path_file\npath_file.unit.description = \"Example path for demonstration purposes\"\npath_file.path.path_exists = \"/tmp/example\"\npath_file.install.wanted_by = \"multi-user.target\"\n\n# Create or update the files\nservice.update()\n```\n\n#### `example.swap`\n```ini\n[Unit]\nDescription=Example swap for demonstration purposes\n\n[Swap]\nWhat=/swapfile\n\n[Install]\nWantedBy=multi-user.target\n```\n\n#### `example.path`\n```ini\n[Unit]\nDescription=Example path for demonstration purposes\n\n[Path]\nPathExists=/tmp/example\n\n[Install]\nWantedBy=multi-user.target\n```\n\n### Example: Creating Slice and Scope Files\n\n```python\n# Configure the slice file\nslice_file = service.slice_file\nslice_file.unit.description = \"Example slice for demonstration purposes\"\n\n# Configure the scope file\nscope_file = service.scope_file\nscope_file.unit.description = \"Example scope for demonstration purposes\"\nscope_file.scope.slice = \"example.slice\"\n\n# Create or update the files\nservice.update()\n```\n\n#### `example.slice`\n```ini\n[Unit]\nDescription=Example slice for demonstration purposes\n```\n\n#### `example.scope`\n```ini\n[Unit]\nDescription=Example scope for demonstration purposes\n\n[Scope]\nSlice=example.slice\n```\n\n### Deleting a Service\n\nTo delete a service and its associated files:\n\n```python\nservice.delete()\n```\n\nThis will remove all files matching the service name in the systemd directory.\n\n## Configuration Options\n\n`service_config_foundry` supports multiple systemd file types, including:\n\n- `.service` - Main service configuration\n- `.socket` - Socket configuration\n- `.timer` - Timer configuration\n- `.mount` - Mount point configuration\n- `.automount` - Automount configuration\n- `.swap` - Swap space configuration\n- `.path` - Path configuration\n- `.slice` - Slice configuration\n- `.scope` - Scope configuration\n\n## Development\n\n### Running Tests\n\nThis project includes comprehensive test coverage using pytest. To run the tests:\n\n```bash\n# Install test dependencies\npip install -e \".[test]\"\n\n# Run all tests\npytest tests/\n\n# Run tests with coverage\npytest tests/ --cov=service_config_foundry --cov-report=term-missing\n\n# Run tests with coverage report in HTML\npytest tests/ --cov=service_config_foundry --cov-report=html\n```\n\n### Development Setup\n\nFor development, install the package in development mode with all dependencies:\n\n```bash\n# Install development dependencies\npip install -e \".[dev]\"\n\n# Install pre-commit hooks\npre-commit install\n\n# Run pre-commit on all files\npre-commit run --all-files\n```\n\n### Using Make Commands\n\nThe project includes a Makefile for common development tasks:\n\n```bash\n# Install for development\nmake dev-install\n\n# Run tests\nmake test\n\n# Run tests with coverage\nmake test-cov\n\n# Format code\nmake format\n\n# Run linting\nmake lint\n\n# Clean build artifacts\nmake clean\n```\n\n### GitHub Actions\n\nThe project includes GitHub Actions workflows that:\n\n- Run tests on every push and pull request\n- Test against multiple Python versions (3.8-3.12)\n- Check code formatting and linting\n- Generate coverage reports\n- Automatically publish to PyPI on tagged releases\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.\n\n## Contributing\n\nContributions are welcome! If you encounter any issues or have suggestions for improvement, please open an issue or submit a pull request.\n\nBefore contributing:\n\n1. Fork the repository\n2. Create a feature branch\n3. Make your changes with appropriate tests\n4. Ensure all tests pass\n5. Submit a pull request\n\n## Contact\n\n- **Author**: Yush Kapoor \n- **Email**: [yushdotkapoor@gmail.com](mailto:yushdotkapoor@gmail.com) \n- **GitHub**: [https://github.com/yushdotkapoor/service_config_foundry](https://github.com/yushdotkapoor/service_config_foundry)\n\n## Acknowledgments\n\nSpecial thanks to the Linux and Python communities for their inspiration and support in creating this project.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Helps create non-templated systemd services.",
"version": "0.5.5",
"project_urls": {
"Bug Tracker": "https://github.com/yushdotkapoor/service_config_foundry/issues",
"Homepage": "https://github.com/yushdotkapoor/service_config_foundry",
"Repository": "https://github.com/yushdotkapoor/service_config_foundry"
},
"split_keywords": [
"systemd",
" service",
" linux",
" system-administration"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "2abd2778b59f694dbec80da805260820e4d58270f235bb35798a0c934480fe96",
"md5": "6ae9ff39a7f09e95b7dd94b61bd07f55",
"sha256": "abb22d049eca5ea74b0aa2387f5eab75fa72085c7f131bfd190ba5d1938b66e5"
},
"downloads": -1,
"filename": "service_config_foundry-0.5.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6ae9ff39a7f09e95b7dd94b61bd07f55",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 17350,
"upload_time": "2025-08-16T21:43:43",
"upload_time_iso_8601": "2025-08-16T21:43:43.287115Z",
"url": "https://files.pythonhosted.org/packages/2a/bd/2778b59f694dbec80da805260820e4d58270f235bb35798a0c934480fe96/service_config_foundry-0.5.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "85f7c12815f4eadbe837574f06dc53928c22a9d33f11868febc594038b625c8c",
"md5": "5342864cc0546186b15f75729796e1c7",
"sha256": "c4b98adef57d34a386aa995a058b81ab5e60fe10424e3ea5fe266adb5fcf4454"
},
"downloads": -1,
"filename": "service_config_foundry-0.5.5.tar.gz",
"has_sig": false,
"md5_digest": "5342864cc0546186b15f75729796e1c7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 34999,
"upload_time": "2025-08-16T21:43:44",
"upload_time_iso_8601": "2025-08-16T21:43:44.715544Z",
"url": "https://files.pythonhosted.org/packages/85/f7/c12815f4eadbe837574f06dc53928c22a9d33f11868febc594038b625c8c/service_config_foundry-0.5.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-16 21:43:44",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "yushdotkapoor",
"github_project": "service-config-foundry",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "service-config-foundry"
}