-
Notifications
You must be signed in to change notification settings - Fork 17
/
ACS::ECS::AttachNASFileSystemToInstance.yml
188 lines (174 loc) · 6.69 KB
/
ACS::ECS::AttachNASFileSystemToInstance.yml
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
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
mount_targets=(
{{mountTargetDomain}}
)
mount_points=(
{{mountDir}}
)
use_v3=(
{{fileSystemVersion}}
)
success_install_client=0
type yum
if [ $? -eq 0 -a $success_install_client -eq 0 ]; then
yum install -y nfs-utils
if [ $? -eq 0 ]; then
success_install_client=1
fi
fi
type apt-get
if [ $? -eq 0 -a $success_install_client -eq 0 ]; then
apt-get install -y nfs-common
if [ $? -eq 0 ]; then
success_install_client=1
else
apt-get updateå
apt-get install -y nfs-common
if [ $? -eq 0 ]; then
success_install_client=1
fi
fi
fi
type zypper
if [ $? -eq 0 -a $success_install_client -eq 0 ]; then
zypper install -y nfs-client
if [ $? -eq 0 ]; then
success_install_client=1
else
zypper refresh
zypper install -y nfs-client
if [ $? -eq 0 ]; then
success_install_client=1
fi
fi
fi
if [ $success_install_client -ne 1 ]; then
exit 0
fi
if (lsmod | grep sunrpc > /dev/null); then
if (modinfo sunrpc | grep tcp_max_slot_table_entries > /dev/null); then
sysctl -w sunrpc.tcp_max_slot_table_entries=128
fi
if (modinfo sunrpc | grep tcp_slot_table_entries > /dev/null); then
sysctl -w sunrpc.tcp_slot_table_entries=128
fi
fi
if (modinfo nfs | grep nfs4_unique_id > /dev/null); then
printf 'install nfs /sbin/modprobe --ignore-install nfs nfs4_unique_id=$(cat /sys/class/dmi/id/product_uuid)\n' > /etc/modprobe.d/alinas.conf
fi
(modinfo sunrpc | grep tcp_max_slot_table_entries > /dev/null) && echo "options sunrpc tcp_max_slot_table_entries=128" >> /etc/modprobe.d/alinas.conf
(modinfo sunrpc | grep tcp_slot_table_entries > /dev/null) && echo "options sunrpc tcp_slot_table_entries=128" >> /etc/modprobe.d/alinas.conf
if [ ! -f /etc/rc.local ]; then
echo '#!/bin/bash' > /etc/rc.local
fi
echo "mount -a -t nfs" >> /etc/rc.local
chmod +x /etc/rc.local
for i in "${!mount_targets[@]}"; do
mount_target=${mount_targets[$i]}
[ -z $mount_target ] && continue
mount_point=${mount_points[$i]}
[ -z $mount_point ] && continue
v3=${use_v3[$i]}
[ -z $v3 ] && continue
mkdir -p "${mount_point}" || continue
automount_param=""
if [ -f /etc/os-release ]; then
os_name=`awk -F= '/^NAME/{print $2}' /etc/os-release`
if [[ ${os_name} == "\"Ubuntu\"" ]]; then
if (man systemd-fstab-generator > /dev/null); then
automount_param=",x-systemd.automount"
fi
elif [[ ${os_name} == "\"Aliyun Linux\"" ]]; then
if (man systemd-fstab-generator > /dev/null); then
automount_param=",x-systemd.automount,x-systemd.requires=systemd-resolved.service,x-systemd.after=systemd-resolved.service"
fi
fi
fi
if [[ $mount_target == *.extreme.nas.aliyuncs.com ]]; then
if [ -f /etc/systemd/system/sockets.target.wants/rpcbind.socket ]; then
sed -i 's/BindIPv6Only=ipv6-only/#BindIPv6Only=ipv6-only/g' /etc/systemd/system/sockets.target.wants/rpcbind.socket
sed -i 's/ListenStream=\[::\]:111/#ListenStream=\[::\]:111/g' /etc/systemd/system/sockets.target.wants/rpcbind.socket
sed -i 's/ListenDatagram=\[::\]:111/#ListenDatagram=\[::\]:111/g' /etc/systemd/system/sockets.target.wants/rpcbind.socket
fi
echo "${mount_target}:/share ${mount_point} nfs vers=3,nolock,noacl,proto=tcp,noresvport,_netdev${automount_param} 0 0" >> /etc/fstab
elif [[ $mount_target == *.nas.aliyuncs.com ]]; then
if [ $v3 -eq 1 ]; then
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
else
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
fi
fi
mount -a -t nfs
done
df -h
Outputs:
commandOutput:
Type: String
ValueSelector: invocationOutput
Outputs:
commandOutput:
Type: String
Value: '{{ attachFileSystemToLinuxInstance.commandOutput }}'