1313fi
1414
1515SERVICE_NAME=" test_service"
16+ CPU_SERVICE_NAME=" cpu_test_service"
1617SERVICE_FILE=" $ZINIT_CONFIG_DIR /$SERVICE_NAME .yaml"
18+ CPU_SERVICE_FILE=" $ZINIT_CONFIG_DIR /$CPU_SERVICE_NAME .yaml"
1719
1820echo " --- Zinit Example Script ---"
1921echo " Zinit binary path: $ZINIT_BIN "
4749 echo " Zinit daemon successfully started."
4850fi
4951
50- # Step 3: Create a sample zinit service file
52+ # Step 3: Create sample zinit service files
5153echo " Creating sample service file: $SERVICE_FILE "
5254cat << EOF > "$SERVICE_FILE "
5355name: $SERVICE_NAME
@@ -61,19 +63,42 @@ if [ $? -ne 0 ]; then
6163fi
6264echo " 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
6986echo " 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
79104echo " --- Script Finished ---"
0 commit comments