weizhouapache commented on code in PR #11654:
URL: https://github.com/apache/cloudstack/pull/11654#discussion_r2358229959
##########
systemvm/debian/opt/cloud/bin/setup/postinit.sh:
##########
@@ -47,6 +47,66 @@ fi
CMDLINE=/var/cache/cloud/cmdline
TYPE=$(grep -Po 'type=\K[a-zA-Z]*' $CMDLINE)
+
+# Execute cloud-init manually if user data is present
+run_cloud_init() {
+ if [ ! -f "$CMDLINE" ]; then
+ log_it "No cmdline file found, skipping cloud-init execution"
+ return 0
+ fi
+
+ local encoded_userdata=$(grep -Po 'userdata=\K[^[:space:]]*' "$CMDLINE" ||
true)
+ if [ -z "$encoded_userdata" ]; then
+ log_it "No user data found in cmdline, skipping cloud-init execution"
+ return 0
+ fi
+
+ log_it "User data detected, setting up and running cloud-init manually"
+
+ # Set up user data files (reuse the function from init.sh)
+ mkdir -p /var/lib/cloud/seed/nocloud
+
+ # Decode and potentially decompress user data
+ local decoded_userdata
+ decoded_userdata=$(echo "$encoded_userdata" | base64 -d 2>/dev/null)
+ if [ $? -ne 0 ] || [ -z "$decoded_userdata" ]; then
+ log_it "ERROR: Failed to decode base64 user data"
+ return 1
+ fi
+
+ # Write user data
+ echo "$decoded_userdata" > /var/lib/cloud/seed/nocloud/user-data
+ chmod 600 /var/lib/cloud/seed/nocloud/user-data
+
+ # Create meta-data
+ local instance_name=$(grep -Po 'name=\K[^[:space:]]*' "$CMDLINE" || hostname)
+ cat > /var/lib/cloud/seed/nocloud/meta-data << EOF
+instance-id: $instance_name
+local-hostname: $instance_name
+EOF
+ chmod 644 /var/lib/cloud/seed/nocloud/meta-data
+
+ log_it "User data files created, executing cloud-init..."
+
+ # Clean any previous cloud-init state
+ cloud-init clean --logs
+
+ # Run cloud-init stages manually
Review Comment:
ok, I think we can let it executed each time during bootup.
maybe add an example how to achieve one-time execution of configuration in
doc, similar to what CKS does
```
if [[ -f "/home/cloud/success" ]]; then
echo "Already provisioned!"
exit 0
fi
...
sudo touch /home/cloud/success
echo "true" > /home/cloud/success
```
I did not consider patch process, do we need to consider it ? @vishesh92
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]