← Back to Codex
Practices Adept

Protocols for Safe Invocation of Daemons (Processes)

Essential safety guidelines for summoning and managing autonomous processes in production environments.

Protocols for Safe Invocation of Daemons (Processes)

Daemons—autonomous processes that run in the background—are among the most powerful tools in a technomancer’s arsenal. They are also among the most dangerous if mishandled.

Understanding Daemons

A daemon is a process that operates independently of direct user interaction. Unlike regular processes, daemons persist across sessions and can continue operating even when their summoner is not present.

The Invocation Ritual

Preparation

Before invoking a daemon, ensure:

  1. Resource Limits: Set appropriate CPU, memory, and I/O limits
  2. Isolation: Run the daemon in a contained environment (container, chroot, or sandbox)
  3. Logging: Establish comprehensive logging to monitor the daemon’s behavior
  4. Monitoring: Set up health checks and alerting mechanisms

The Invocation

# Example: Invoking a daemon with proper safeguards
systemd-run --unit=my-daemon \
  --setenv=ENVIRONMENT=production \
  --property=MemoryLimit=512M \
  --property=CPUQuota=50% \
  ./daemon-binary

Binding and Control

Once invoked, a daemon must be properly bound:

  • PID Files: Maintain process ID files for reliable control
  • Signal Handlers: Implement graceful shutdown handlers
  • State Management: Ensure the daemon can recover from failures

Common Pitfalls

  1. Zombie Processes: Daemons that exit but are not properly reaped
  2. Resource Leaks: Daemons that consume increasing resources over time
  3. Orphaned Processes: Daemons that lose their controlling terminal
  4. Race Conditions: Multiple daemons competing for the same resources

Best Practices

  • Always use process managers (systemd, supervisor, etc.)
  • Implement idempotency in daemon operations
  • Use health checks and automatic restart policies
  • Monitor resource usage continuously
  • Document all daemon configurations

The Banishment Ritual

When a daemon must be terminated:

  1. Send a graceful shutdown signal (SIGTERM)
  2. Wait for a reasonable timeout period
  3. If the daemon persists, escalate to SIGKILL
  4. Clean up all resources (files, sockets, locks)
  5. Verify the daemon has been fully banished

Remember: A daemon that is not properly banished can become a ghost process, consuming resources indefinitely.