Skip to content

[FEATURE]: OS service management - systemd, launchd, and Windows service support #1673

@crivetimihai

Description

@crivetimihai

Summary

Implement OS-level service management for ContextForge, enabling it to run as a managed system service with proper lifecycle management (start, stop, restart, enable, disable).

Motivation

Currently, ContextForge must be started manually or via container orchestration. For bare-metal or VM deployments, users need proper OS integration to:

  • Auto-start on boot
  • Graceful shutdown handling
  • Service health monitoring
  • Log integration with system journals
  • Standard service management commands

Proposed Implementation

1. Systemd (Linux)

Create a systemd service unit file (contextforge.service):

  • Type=notify or Type=simple with proper readiness signaling
  • Socket activation support (optional)
  • Hardening options (PrivateTmp, NoNewPrivileges, etc.)
  • Proper dependency ordering (After=network-online.target)
  • Environment file support (/etc/contextforge/contextforge.env)
  • User/group configuration (run as non-root)

2. Launchd (macOS)

Create a launchd plist file (com.contextforge.gateway.plist):

  • KeepAlive with proper restart policies
  • StandardOutPath/StandardErrorPath for logging
  • Environment variables support
  • User agent or system daemon options

3. Windows Service (Optional)

Consider pywin32 or NSSM wrapper for Windows service support:

  • Service registration and removal
  • Start/stop/restart commands
  • Event log integration

4. CLI Commands

Extend mcpgateway CLI with service management:

mcpgateway service install    # Install service files
mcpgateway service uninstall  # Remove service files
mcpgateway service start      # Start the service
mcpgateway service stop       # Stop the service
mcpgateway service restart    # Restart the service
mcpgateway service status     # Show service status
mcpgateway service enable     # Enable auto-start on boot
mcpgateway service disable    # Disable auto-start on boot
mcpgateway service logs       # Show/tail service logs

5. Installation Scripts

  • scripts/install-service.sh for Linux/macOS
  • scripts/install-service.ps1 for Windows (if supported)
  • Makefile targets: make install-service, make uninstall-service

Configuration

Service configuration via environment or config file:

# /etc/contextforge/contextforge.env
MCPGATEWAY_USER=contextforge
MCPGATEWAY_GROUP=contextforge
MCPGATEWAY_WORKDIR=/var/lib/contextforge
MCPGATEWAY_CONFIG=/etc/contextforge/config.yaml
MCPGATEWAY_PORT=4444

Acceptance Criteria

  • Systemd service file with hardening options
  • Launchd plist for macOS support
  • CLI commands for service lifecycle management
  • Installation/uninstallation scripts
  • Documentation for service deployment
  • Graceful shutdown signal handling (SIGTERM)
  • Health check integration for systemd watchdog (optional)
  • SELinux/AppArmor policy considerations documented

Related

  • Container deployment already handles this via orchestration
  • Kubernetes deployment uses native pod lifecycle
  • This addresses bare-metal/VM deployment scenarios

Labels

enhancement, devops, deployment

Metadata

Metadata

Assignees

No one assigned

    Labels

    SHOULDP2: Important but not vital; high-value items that are not crucial for the immediate releasechoreLinting, formatting, dependency hygiene, or project maintenance choresenhancementNew feature or request
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions