working example to showcase zinit usage in Rhai scripts
This commit is contained in:
@@ -7,13 +7,19 @@ let socket_path = "/var/run/zinit.sock";
|
||||
print("Listing all services:");
|
||||
let services = zinit_list(socket_path);
|
||||
|
||||
for (name, state) in services {
|
||||
print(`${name}: ${state}`);
|
||||
if services.is_empty() {
|
||||
print("No services found.");
|
||||
} else {
|
||||
// Iterate over the keys of the map
|
||||
for name in services.keys() {
|
||||
let state = services[name];
|
||||
print(`${name}: ${state}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Get status of a specific service
|
||||
let service_name = "example-service";
|
||||
print(`\nGetting status for ${service_name}:`);
|
||||
let service_name = "test";
|
||||
print(`Getting status for ${service_name}:`);
|
||||
|
||||
try {
|
||||
let status = zinit_status(socket_path, service_name);
|
||||
@@ -23,7 +29,7 @@ try {
|
||||
print(`Target: ${status.target}`);
|
||||
print("Dependencies:");
|
||||
|
||||
for (dep, state) in status.after {
|
||||
for (dep, state) in status.after.keys() {
|
||||
print(` ${dep}: ${state}`);
|
||||
}
|
||||
} catch(err) {
|
||||
@@ -50,16 +56,27 @@ try {
|
||||
let start_result = zinit_start(socket_path, new_service);
|
||||
print(`Service started: ${start_result}`);
|
||||
|
||||
// Get logs
|
||||
// Get logs for a specific service
|
||||
print("\nGetting logs:");
|
||||
let logs = zinit_logs(socket_path, new_service);
|
||||
|
||||
for log in logs {
|
||||
print(log);
|
||||
}
|
||||
|
||||
// Or to get all logs (uncomment if needed)
|
||||
// print("\nGetting all logs:");
|
||||
// let all_logs = zinit_logs_all(socket_path);
|
||||
//
|
||||
// for log in all_logs {
|
||||
// print(log);
|
||||
// }
|
||||
|
||||
// Clean up
|
||||
print("\nCleaning up:");
|
||||
let stop_result = zinit_stop(socket_path, new_service);
|
||||
print(`Service stopped: ${stop_result}`);
|
||||
|
||||
let forget_result = zinit_forget(socket_path, new_service);
|
||||
print(`Service forgotten: ${forget_result}`);
|
||||
|
||||
@@ -67,4 +84,4 @@ try {
|
||||
print(`Service deleted: ${delete_result}`);
|
||||
} catch(err) {
|
||||
print(`Error: ${err}`);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user