This topic describes the cause of and solution to the following issue: The user data of a Linux instance does not take effect, and the "Failed to run module scripts-user(scripts in /var/lib/cloud/instance/scripts)" error message appears in the system logs.
Problem description
After you configure user data for a Linux instance and restart the instance, the configured user data does not take effect and the following error message appears in the system logs: Failed to run module scripts-user(scripts in /var/lib/cloud/instance/scripts). The error message indicates that the user data script failed to run in cloud-init on instance startup.

For information about how to view the system logs and screenshots of an instance, see View system logs and screenshots.
Cause
This issue may occur due to errors in the user data script that was passed into the Linux instance, such as an invalid syntax format or an error that occurred while running the user data script.
Solution
You can use various scripts or files as user data scripts for the Linux instance. The scripts have different characteristics and are subject to different user data conventions. Troubleshoot the user data script of the Linux instance based on the user data conventions that apply to the script.
User-Data scripts
- The first line starts with a number sign and an exclamation mark (
#!). - User-data scripts are run once only the first time the instance starts.
#!/bin/sh
echo "Hello World. The time is now $(date -R)!" | tee /root/userdata_test.txtThe example user-data script can be run to write the system time to the userdata_test.txt file the first time the instance starts.
If a User-Data script fails to run, you can run the following common Cloud Assistant command to obtain the error logs about the failure: ACS-ECS-UserData-Check-for-linux.sh. If an error message appears in the logs, an error occurs while running the script. If an error message does not appear in the logs, the script runs as expected. Check the script from other aspects to identify the cause of the issue. For information about common Cloud Assistant commands, see View and run common commands.
Cloud Config data
- The first line starts with
#cloud-config, and the header cannot include spaces. - The script must follow the YAML syntax.
- The frequency at which the user data is run varies based on your configured modules. For example, if you configure the Apt Configure module, the user data is run only once for each instance. If you configure the Bootcmd module, the user data is run each time the instance starts.
#cloud-config
apt:
primary:
- arches: [default]
uri: https://us.archive.ubuntu.com/ubuntu/
bootcmd:
- echo "Hello World. The time is now $(date -R)!" | tee /root/userdata_test.txtThe example cloud-config data can be run to modify the default software repository and write the latest system time to the userdata_test.txt file each time the instance starts.
Include files
- The first line starts with
#include, and the header cannot include spaces. - Each script cannot exceed 16 KB in size before it is encoded in Base64.
- The frequency at which the user data is run varies based on the types of scripts and modules.
#include
https://ecs-image-test.oss-cn-hangzhou.aliyuncs.com/userdata/myscript.shThe example include file contains a script link. The running frequency is determined by the type of the script. For example, if the script is a user-data script, the script is run once only the first time the instance starts.
Gzip compressed content
.gz format, create a link to the gzip compressed content, and then pass in the link as an include file. cloud-init automatically decompresses the gzip compressed content. The result of running the decompressed content shows no difference from that of running a script that is directly passed in. Gzip compressed content has the following characteristics: - The first line starts with
#include, and the header cannot include spaces. - The size of the gzip compressed content cannot exceed 16 KB before it is encoded in Base64.
- The frequency at which the user data is run varies based on the types of scripts and modules.
#include
https://ecs-image-test.oss-cn-hangzhou.aliyuncs.com/userdata/myscript.gzThe example include file contains a link to gzip compressed content. cloud-init reads the gzip compressed content and automatically decompresses and runs it. The running frequency is determined by the script type. For example, if the gzip compressed content is obtained by compressing a user-data script, the gzip compressed content is run once only the first time the instance starts.
Upstart Job
- The first line starts with
#upstart-job, and the header cannot include spaces. - Upstart job scripts are run each time the instance starts.
#upstart-job
description "upstart test"
start on runlevel [2345] #Starts at run levels 2, 3, 4, and 5.
stop on runlevel [!2345] #Stops at run levels other than 2, 3, 4, and 5.
exec echo "Hello World. The time is now $(date -R)!" | tee /root/output.txtFor sample user data, see Manage the user data of Linux instances.