-
Notifications
You must be signed in to change notification settings - Fork 17
/
ACS::ECS::AttachNASFileSystemToInstance.json
102 lines (102 loc) · 6.66 KB
/
ACS::ECS::AttachNASFileSystemToInstance.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
{
"FormatVersion": "OOS-2019-06-01",
"Description": {
"name-en": "ACS::ECS::AttachNASFileSystemToInstance",
"name-zh-cn": "挂载NAS文件系统到ECS实例",
"en": "Attach NAS file system to instance (only supports elastic expansion activities)",
"zh-cn": "将NAS文件系统挂载到ECS实例(仅支持弹性扩张活动)"
},
"Parameters": {
"regionId": {
"Description": {
"en": "The ID of region",
"zh-cn": "地域ID"
},
"Type": "String"
},
"instanceId": {
"Description": {
"en": "The ID of ECS instance",
"zh-cn": "ECS实例ID"
},
"Type": "String"
},
"mountTargetDomain": {
"Description": {
"en": "The MountTargetDomain",
"zh-cn": "挂载点域名"
},
"Type": "String"
},
"mountDir": {
"Description": {
"en": "The dir to mount file systen in instance",
"zh-cn": "实例中文件系统的挂载目录"
},
"Type": "String",
"Default": "/mnt"
},
"fileSystemVersion": {
"Description": {
"en": "The version of file system",
"zh-cn": "文件系统的版本"
},
"Type": "String",
"AllowedValues": [
0,
1
],
"Default": 0
}
},
"Tasks": [
{
"Name": "untilInstanceReady",
"Action": "ACS::WaitFor",
"Description": {
"en": "Waits for the ECS instance to enter Running status",
"zh-cn": "等待ECS实例到达运行中状态"
},
"Properties": {
"Service": "ECS",
"API": "DescribeInstances",
"Parameters": {
"RegionId": "{{ regionId }}",
"InstanceIds": [
"{{ instanceId }}"
]
},
"DesiredValues": [
"Running"
],
"PropertySelector": "Instances.Instance[].Status"
}
},
{
"Name": "attachFileSystemToLinuxInstance",
"Action": "ACS::ECS::RunCommand",
"Description": {
"en": "Attaches file system to ECS instance",
"zh-cn": "挂载文件系统到ECS实例"
},
"Properties": {
"instanceId": "{{ instanceId }}",
"regionId": "{{ regionId }}",
"commandType": "RunShellScript",
"commandContent": "#!/bin/bash\nmount_targets=(\n {{mountTargetDomain}}\n)\nmount_points=(\n {{mountDir}}\n)\nuse_v3=(\n {{fileSystemVersion}}\n)\n\nsuccess_install_client=0\n\ntype yum\nif [ $? -eq 0 -a $success_install_client -eq 0 ]; then\n yum install -y nfs-utils\n if [ $? -eq 0 ]; then\n success_install_client=1\n fi\nfi\n\ntype apt-get\nif [ $? -eq 0 -a $success_install_client -eq 0 ]; then\n apt-get install -y nfs-common\n if [ $? -eq 0 ]; then\n success_install_client=1\n else\n apt-get updateå\n apt-get install -y nfs-common\n if [ $? -eq 0 ]; then\n success_install_client=1\n fi\n fi\nfi\n\ntype zypper\nif [ $? -eq 0 -a $success_install_client -eq 0 ]; then\n zypper install -y nfs-client\n if [ $? -eq 0 ]; then\n success_install_client=1\n else\n zypper refresh\n zypper install -y nfs-client\n if [ $? -eq 0 ]; then\n success_install_client=1\n fi\n fi\nfi\n\nif [ $success_install_client -ne 1 ]; then\n exit 0\nfi\n\nif (lsmod | grep sunrpc > /dev/null); then\n if (modinfo sunrpc | grep tcp_max_slot_table_entries > /dev/null); then\n sysctl -w sunrpc.tcp_max_slot_table_entries=128\n fi\n if (modinfo sunrpc | grep tcp_slot_table_entries > /dev/null); then\n sysctl -w sunrpc.tcp_slot_table_entries=128\n fi\nfi\n\nif (modinfo nfs | grep nfs4_unique_id > /dev/null); then\n printf 'install nfs /sbin/modprobe --ignore-install nfs nfs4_unique_id=$(cat /sys/class/dmi/id/product_uuid)\\n' > /etc/modprobe.d/alinas.conf\nfi\n(modinfo sunrpc | grep tcp_max_slot_table_entries > /dev/null) && echo \"options sunrpc tcp_max_slot_table_entries=128\" >> /etc/modprobe.d/alinas.conf\n(modinfo sunrpc | grep tcp_slot_table_entries > /dev/null) && echo \"options sunrpc tcp_slot_table_entries=128\" >> /etc/modprobe.d/alinas.conf\n\nif [ ! -f /etc/rc.local ]; then\n echo '#!/bin/bash' > /etc/rc.local\nfi\necho \"mount -a -t nfs\" >> /etc/rc.local\nchmod +x /etc/rc.local\n\nfor i in \"${!mount_targets[@]}\"; do\n mount_target=${mount_targets[$i]}\n [ -z $mount_target ] && continue\n mount_point=${mount_points[$i]}\n [ -z $mount_point ] && continue\n v3=${use_v3[$i]}\n [ -z $v3 ] && continue\n\n mkdir -p \"${mount_point}\" || continue\n\n automount_param=\"\"\n if [ -f /etc/os-release ]; then\n os_name=`awk -F= '/^NAME/{print $2}' /etc/os-release`\n if [[ ${os_name} == \"\\\"Ubuntu\\\"\" ]]; then\n if (man systemd-fstab-generator > /dev/null); then\n automount_param=\",x-systemd.automount\"\n fi\n elif [[ ${os_name} == \"\\\"Aliyun Linux\\\"\" ]]; then\n if (man systemd-fstab-generator > /dev/null); then\n automount_param=\",x-systemd.automount,x-systemd.requires=systemd-resolved.service,x-systemd.after=systemd-resolved.service\"\n fi\n fi\n fi\n\n if [[ $mount_target == *.extreme.nas.aliyuncs.com ]]; then\n if [ -f /etc/systemd/system/sockets.target.wants/rpcbind.socket ]; then\n sed -i 's/BindIPv6Only=ipv6-only/#BindIPv6Only=ipv6-only/g' /etc/systemd/system/sockets.target.wants/rpcbind.socket\n sed -i 's/ListenStream=\\[::\\]:111/#ListenStream=\\[::\\]:111/g' /etc/systemd/system/sockets.target.wants/rpcbind.socket\n sed -i 's/ListenDatagram=\\[::\\]:111/#ListenDatagram=\\[::\\]:111/g' /etc/systemd/system/sockets.target.wants/rpcbind.socket\n fi\n echo \"${mount_target}:/share ${mount_point} nfs vers=3,nolock,noacl,proto=tcp,noresvport,_netdev${automount_param} 0 0\" >> /etc/fstab\n elif [[ $mount_target == *.nas.aliyuncs.com ]]; then\n if [ $v3 -eq 1 ]; then\n echo \"${mount_target}:/ ${mount_point} nfs vers=3,nolock,proto=tcp,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,_netdev,noresvport${automount_param} 0 0\" >> /etc/fstab\n else\n echo \"${mount_target}:/ ${mount_point} nfs vers=4,minorversion=0,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,_netdev,noresvport${automount_param} 0 0\" >> /etc/fstab\n fi\n fi\n\n mount -a -t nfs\ndone\n\ndf -h"
},
"Outputs": {
"commandOutput": {
"Type": "String",
"ValueSelector": "invocationOutput"
}
}
}
],
"Outputs": {
"commandOutput": {
"Type": "String",
"Value": "{{ attachFileSystemToLinuxInstance.commandOutput }}"
}
}
}