Skip to content
This repository was archived by the owner on Dec 15, 2025. It is now read-only.

Commit 006c9fa

Browse files
committed
...
1 parent 1d1ba60 commit 006c9fa

1 file changed

Lines changed: 31 additions & 6 deletions

File tree

example/example.sh

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ else
1313
fi
1414

1515
SERVICE_NAME="test_service"
16+
CPU_SERVICE_NAME="cpu_test_service"
1617
SERVICE_FILE="$ZINIT_CONFIG_DIR/$SERVICE_NAME.yaml"
18+
CPU_SERVICE_FILE="$ZINIT_CONFIG_DIR/$CPU_SERVICE_NAME.yaml"
1719

1820
echo "--- Zinit Example Script ---"
1921
echo "Zinit binary path: $ZINIT_BIN"
@@ -47,7 +49,7 @@ else
4749
echo "Zinit daemon successfully started."
4850
fi
4951

50-
# Step 3: Create a sample zinit service file
52+
# Step 3: Create sample zinit service files
5153
echo "Creating sample service file: $SERVICE_FILE"
5254
cat <<EOF > "$SERVICE_FILE"
5355
name: $SERVICE_NAME
@@ -61,19 +63,42 @@ if [ $? -ne 0 ]; then
6163
fi
6264
echo "Service file created."
6365

64-
# Step 4: Tell zinit to monitor the new service
65-
echo "Telling zinit to monitor the service..."
66+
# Create a CPU-intensive service with child processes
67+
echo "Creating CPU-intensive service file: $CPU_SERVICE_FILE"
68+
cat <<EOF > "$CPU_SERVICE_FILE"
69+
name: $CPU_SERVICE_NAME
70+
exec: /bin/bash -c "for i in {1..3}; do (openssl speed -multi 2 &) ; done; while true; do sleep 10; done"
71+
log: stdout
72+
EOF
73+
74+
if [ $? -ne 0 ]; then
75+
echo "Error: Failed to create CPU service file $CPU_SERVICE_FILE. Exiting."
76+
exit 1
77+
fi
78+
echo "CPU service file created."
79+
80+
# Step 4: Tell zinit to monitor the new services
81+
echo "Telling zinit to monitor the services..."
6682
"$ZINIT_BIN" monitor "$SERVICE_NAME"
83+
"$ZINIT_BIN" monitor "$CPU_SERVICE_NAME"
6784

6885
# Step 5: List services to verify the new service is recognized
6986
echo "Listing zinit services to verify..."
7087
"$ZINIT_BIN" list
7188

72-
# # Step 6: Clean up (optional, but good for examples)
73-
# echo "Cleaning up: stopping and forgetting $SERVICE_NAME..."
89+
# Step 6: Show stats for the CPU-intensive service
90+
echo "Waiting for services to start and generate some stats..."
91+
sleep 5
92+
echo "Getting stats for $CPU_SERVICE_NAME..."
93+
"$ZINIT_BIN" stats "$CPU_SERVICE_NAME"
94+
95+
# # Step 7: Clean up (optional, but good for examples)
96+
# echo "Cleaning up: stopping and forgetting services..."
7497
# "$ZINIT_BIN" stop "$SERVICE_NAME" > /dev/null 2>&1
7598
# "$ZINIT_BIN" forget "$SERVICE_NAME" > /dev/null 2>&1
76-
# rm -f "$SERVICE_FILE"
99+
# "$ZINIT_BIN" stop "$CPU_SERVICE_NAME" > /dev/null 2>&1
100+
# "$ZINIT_BIN" forget "$CPU_SERVICE_NAME" > /dev/null 2>&1
101+
# rm -f "$SERVICE_FILE" "$CPU_SERVICE_FILE"
77102
# echo "Cleanup complete."
78103

79104
echo "--- Script Finished ---"

0 commit comments

Comments
 (0)