#!/usr/bin/env zinit
//! Complete Production Example
//!
//! Full-featured example with system services, logging, and health monitoring
let z = zinit.log_level(2).connect();
print("=== Complete Production Setup ===");
print("");
// System service for logging (system class, protected from bulk ops)
print("1. Setting up logging service:");
z.service_new()
.name("log_aggregator")
.exec("rsyslog")
.class("system")
.critical(true)
.restart("always")
.register();
// Database service with persistent logging
print("");
print("2. Setting up database:");
z.service_new()
.name("postgres")
.exec("postgres -D /var/lib/postgres")
.class("system")
.critical(true)
.after("log_aggregator")
.health_tcp("127.0.0.1:5432")
.health_interval_ms(10000)
.health_retries(3)
.restart("on-failure")
.restart_delay_ms(5000)
.start_timeout_ms(30000)
.log_buffer_lines(5000)
.log_file("/var/log/postgres.log")
.register();
// Cache service
print("");
print("3. Setting up cache:");
z.service_new()
.name("redis")
.exec("redis-server --port 6379")
.after("log_aggregator")
.health_tcp("127.0.0.1:6379")
.health_interval_ms(5000)
.restart("on-failure")
.register();
// Main API service
print("");
print("4. Setting up API server:");
z.service_new()
.name("api")
.exec("node /app/server.js")
.dir("/app")
.env("NODE_ENV", "production")
.env("DB_HOST", "localhost")
.env("REDIS_HOST", "localhost")
.requires("postgres")
.requires("redis")
.after("postgres")
.after("redis")
.health_http("http://localhost:3000/health")
.health_expect_status(200)
.health_interval_ms(10000)
.health_timeout_ms(5000)
.health_retries(3)
.restart("always")
.restart_delay_ms(5000)
.restart_delay_max_ms(60000)
.max_restarts(0)
.stability_period_ms(60000)
.start_timeout_ms(30000)
.stop_timeout_ms(10000)
.log_buffer_lines(10000)
.register();
// Worker service
print("");
print("5. Setting up background workers:");
z.service_new()
.name("workers")
.exec("node /app/workers.js")
.dir("/app")
.env("NODE_ENV", "production")
.env("DB_HOST", "localhost")
.wants("redis")
.after("api")
.restart("on-failure")
.log_buffer_lines(2000)
.register();
print("");
print("6. Starting core services:");
z.start("log_aggregator");
z.start("postgres");
z.start("redis");
z.start("api");
z.start("workers");
print("");
print("7. Viewing service status:");
let services = z.list();
for svc in services {
let status = z.status(svc);
print(" " + svc + ": " + status.state);
}
print("");
print("✓ Production setup complete");