sal/service_manager/examples
2025-07-02 05:50:18 +02:00
..
README.md service manager add examples and improvements 2025-07-02 05:50:18 +02:00
service_spaghetti.rs service manager add examples and improvements 2025-07-02 05:50:18 +02:00
simple_service.rs service manager add examples and improvements 2025-07-02 05:50:18 +02:00

Service Manager Examples

This directory contains examples demonstrating the usage of the sal-service-manager crate.

Running Examples

To run any example, use the following command structure from the service_manager crate's root directory:

cargo run --example <EXAMPLE_NAME>

1. simple_service

This example demonstrates the ideal, clean lifecycle of a service using the separated create and start steps.

Behavior:

  1. Creates a new service definition.
  2. Starts the newly created service.
  3. Checks its status to confirm it's running.
  4. Stops the service.
  5. Checks its status again to confirm it's stopped.
  6. Removes the service definition.

Run it:

cargo run --example simple_service

2. service_spaghetti

This example demonstrates how the service manager handles "messy" or improper sequences of operations, showcasing its error handling and robustness.

Behavior:

  1. Creates a service.
  2. Starts the service.
  3. Tries to start the same service again (which should fail as it's already running).
  4. Removes the service without stopping it first (the manager should handle this gracefully).
  5. Tries to stop the already removed service (which should fail).
  6. Tries to remove the service again (which should also fail).

Run it:

cargo run --example service_spaghetti