Skip to content
kellybrianxPublic

About

create repo and update repo automatically on file activity

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

RPM Repository Service

A FastAPI-based service that automatically maintains an RPM repository by monitoring a directory for new RPM files and updating the repository metadata in real-time.

Features

  • Automatic Repository Updates: Monitors a directory for new RPM files and automatically updates repository metadata
  • RESTful API: Provides HTTP endpoints for repository management and status monitoring
  • Systemd Integration: Runs as a system service with proper logging and restart capabilities
  • File Serving: Serves RPM files and repository metadata via HTTP
  • Health Monitoring: Built-in health checks and status endpoints
  • Security: Runs as a dedicated user with restricted permissions

Requirements

  • Python 3.7+
  • createrepo or createrepo_c package
  • Systemd (for service management)

Installation

Quick Install

Run the installation script as root:

sudo ./install.sh

Manual Installation

  1. Install system dependencies:

    # On Fedora/RHEL/CentOS
    sudo dnf install python3 python3-pip python3-venv createrepo_c
    
    # On Ubuntu/Debian
    sudo apt install python3 python3-pip python3-venv createrepo
  2. Create service user:

    sudo useradd -r -s /bin/false -d /opt/rpm-repo-service rpmrepo
  3. Install Python dependencies:

    cd /opt/rpm-repo-service
    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
  4. Install systemd service:

    sudo cp rpm-repo-service.service /etc/systemd/system/
    sudo systemctl daemon-reload
    sudo systemctl enable rpm-repo-service

Configuration

The service can be configured using environment variables in the systemd service file (/etc/systemd/system/rpm-repo-service.service):

  • RPM_REPO_DIR: Directory to monitor for RPM files (default: /var/lib/rpm-repo)
  • RPM_REPO_NAME: Name of the repository (default: custom-repo)
  • SERVICE_PORT: Port for the HTTP service (default: 8000)
  • GPG_KEY_ID: GPG key ID for signing (optional)

Usage

Starting the Service

sudo systemctl start hygge-rpm-repo.service

Service Management

The service is configured to start automatically on system boot. You can manage it using:

Using systemctl directly:

sudo systemctl start hygge-rpm-repo.service
sudo systemctl stop hygge-rpm-repo.service
sudo systemctl restart hygge-rpm-repo.service
sudo systemctl status hygge-rpm-repo.service
sudo systemctl enable hygge-rpm-repo.service    # Enable on boot
sudo systemctl disable hygge-rpm-repo.service   # Disable on boot

Using the management script:

./manage_service.sh start
./manage_service.sh stop
./manage_service.sh restart
./manage_service.sh status
./manage_service.sh test
./manage_service.sh logs

Viewing logs:

# View recent logs
sudo journalctl -u hygge-rpm-repo.service

# Follow logs in real-time
sudo journalctl -u hygge-rpm-repo.service -f

# Show only errors and warnings
sudo journalctl -u hygge-rpm-repo.service -p err..warning

# Show logs from today
sudo journalctl -u hygge-rpm-repo.service --since today

Using the monitoring script:

./monitor_service.sh logs       # Show recent logs
./monitor_service.sh follow     # Follow logs in real-time
./monitor_service.sh errors     # Show errors and warnings
./monitor_service.sh health     # Comprehensive health check
./monitor_service.sh rpm-events # Show RPM detection events

Checking Service Status

sudo systemctl status hygge-rpm-repo.service

Viewing Logs

# Real-time logs
sudo journalctl -u rpm-repo-service -f

# Log file
sudo tail -f /var/log/rpm-repo-service.log

Adding RPM Files

Simply copy RPM files to the monitored directory:

sudo cp your-package.rpm /var/lib/rpm-repo/

The service will automatically detect the new file and update the repository metadata.

API Endpoints

Health Check

GET /health

Returns the health status of the service.

Repository Status

GET /status

Returns detailed information about the repository including:

  • Repository path
  • Last update time
  • Number of RPM files
  • Monitoring status

Manual Repository Update

POST /update

Manually triggers a repository update.

Repository Access

GET /repo/

Serves the repository directory listing.

GET /repo/{filename}

Serves individual RPM files.

GET /repo/repodata/{filename}

Serves repository metadata files.

Repository Configuration

To use this repository with dnf or yum, create a repository configuration file:

sudo tee /etc/yum.repos.d/hygge-repo.repo << EOF
[hygge-repo]
name=Hygge RPM Repository
baseurl=http://your-server:9999/repo/
enabled=1
gpgcheck=0
EOF

Then install packages:

sudo dnf install your-package

Listing Repository Contents

Once the repository is configured, you can list available packages and files using dnf tools:

List All Available Packages

# List all packages in the repository
dnf list available --repo hygge-repo

# List all packages (including installed ones) from the repository
dnf list --repo hygge-repo

Shows all available package in the repository: dnf repoquery --repo hygge-repo

Search for Specific Packages

# Search for packages by name
dnf search package-name --repo hygge-repo

# Search for packages by description
dnf search "description keywords" --repo hygge-repo

Get Package Information

# Show detailed information about a package
dnf info package-name --repo hygge-repo

# Show what files a package would install
dnf repoquery -l package-name --repo hygge-repo

List Repository Metadata

# Show repository information
dnf repoinfo hygge-repo

# List all repositories (including hygge-repo)
dnf repolist

# List only enabled repositories
dnf repolist enabled

Advanced Package Queries

# List all packages that provide a specific file
dnf provides /path/to/file --repo hygge-repo

# List packages by architecture
dnf list available --repo hygge-repo | grep x86_64

# List packages by version
dnf list available --repo hygge-repo | grep "1.0"

Repository Statistics

# Count total packages in the repository
dnf list available --repo hygge-repo | wc -l

# Show repository size and package count
dnf repoinfo hygge-repo -v

Security Considerations

  • The service runs as a dedicated user (rpmrepo) with minimal privileges
  • Repository directory permissions are restricted to the service user
  • The service uses systemd security features like NoNewPrivileges and PrivateTmp
  • Consider setting up GPG signing for production use

Troubleshooting

Service Won't Start

  1. Check the service status:

    sudo systemctl status rpm-repo-service
  2. Check logs for errors:

    sudo journalctl -u rpm-repo-service --no-pager
  3. Verify the repository directory exists and has correct permissions:

    ls -la /var/lib/rpm-repo

Repository Not Updating

  1. Check if the service is monitoring the directory:

    curl http://localhost:9999/status
  2. Verify file permissions in the repository directory:

    ls -la /var/lib/rpm-repo/
  3. Manually trigger an update:

    curl -X POST http://localhost:9999/update

Permission Issues

Ensure the service user owns the repository directory:

sudo chown -R rpmrepo:rpmrepo /var/lib/rpm-repo

Development

Running in Development Mode

# Install dependencies
pip install -r requirements.txt

# Set environment variables
export RPM_REPO_DIR=/tmp/test-repo
export SERVICE_PORT=8000

# Run the service
python rpm_repo_service.py

Testing

Test the API endpoints:

# Health check
curl http://localhost:9999/health

# Repository status
curl http://localhost:9999/status

# Add a test RPM file
cp some-package.rpm /tmp/test-repo/

License

This project is licensed under the MIT License.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

Support

For issues and questions, please open an issue in the project repository.

About

create repo and update repo automatically on file activity

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages