// Basic Service Manager Usage Example // // This example demonstrates the basic API of the service manager. // It works on both macOS (launchctl) and Linux (zinit/systemd). // // Prerequisites: // // Linux: The service manager will automatically discover running zinit servers // or fall back to systemd. To use zinit, start it with: // zinit -s /tmp/zinit.sock init // // You can also specify a custom socket path: // export ZINIT_SOCKET_PATH=/your/custom/path/zinit.sock // // macOS: No additional setup required (uses launchctl). // // Usage: // herodo examples/service_manager/basic_usage.rhai // Service Manager Basic Usage Example // This example uses the SAL service manager through Rhai integration print("šŸš€ Basic Service Manager Usage Example"); print("======================================"); // Create a service manager for the current platform let manager = create_service_manager(); print("šŸŽ Using service manager for current platform"); // Create a simple service configuration let config = #{ name: "example-service", binary_path: "/bin/echo", args: ["Hello from service manager!"], working_directory: "/tmp", environment: #{ "EXAMPLE_VAR": "hello_world" }, auto_restart: false }; print("\nšŸ“ Service Configuration:"); print(` Name: ${config.name}`); print(` Binary: ${config.binary_path}`); print(` Args: ${config.args}`); // Start the service print("\nšŸš€ Starting service..."); start(manager, config); print("āœ… Service started successfully"); // Check service status print("\nšŸ“Š Checking service status..."); let status = status(manager, "example-service"); print(`Status: ${status}`); // List all services print("\nšŸ“‹ Listing all managed services..."); let services = list(manager); print(`Found ${services.len()} services:`); for service in services { print(` - ${service}`); } // Get service logs print("\nšŸ“„ Getting service logs..."); let logs = logs(manager, "example-service", 5); if logs.trim() == "" { print("No logs available"); } else { print(`Logs:\n${logs}`); } // Stop the service print("\nšŸ›‘ Stopping service..."); stop(manager, "example-service"); print("āœ… Service stopped"); // Remove the service print("\nšŸ—‘ļø Removing service..."); remove(manager, "example-service"); print("āœ… Service removed"); print("\nšŸŽ‰ Example completed successfully!");