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
|
Description: Microsoft provided walinuxagent does not include the
required UFS module, is not resolvconf aware, and does not provide
an upstart script; this patch fixes all of that.
Author: Ben Howard <ben.howard@ubuntu.com>
Bug-Ubuntu: https://bugs.launchpad.net/bugs/1014864
Forwarded: yes
--- a/waagent
+++ b/waagent
@@ -1970,6 +1970,26 @@ esac
exit $RETVAL
"""
+Init_Ubuntu = """\
+#walinuxagent - start Windows Azure agent
+
+description "walinuxagent"
+author "Ben Howard <ben.howard@canonical.com>"
+
+start on (filesystem and started rsyslog)
+
+pre-start script
+ if [ ! -x /usr/sbin/waagent ]; then
+ exit 1
+ fi
+
+ #Load the udf module
+ modprobe -b udf
+end script
+
+exec /usr/sbin/waagent -daemon
+"""
+
Init_Debian = """\
#!/bin/sh
### BEGIN INIT INFO
@@ -2135,18 +2155,30 @@ def Install():
os.remove(GetLastPathElement(a))
shutil.move(a, ".")
Warn("Moved " + a + " -> " + LibDir + "/" + GetLastPathElement(a) )
- filename = "waagent"
- filepath = "/etc/init.d/" + filename
- distro = IsRedHat() + IsDebian() * 2 + IsSuse() * 3
- if distro == 0:
- Error("Unable to detect Linux Distribution.")
- return 1
- init = [[Init_RedHat, "chkconfig --add " + filename],
- [Init_Debian, "update-rc.d " + filename + " defaults"],
- [Init_Suse, "insserv " + filename]][distro - 1]
- SetFileContents(filepath, init[0])
- os.chmod(filepath, 0755)
- Run(init[1])
+
+ if IsUbuntu():
+ # Support for Ubuntu's upstart configuration
+ filename="waagent.conf"
+ filepath = "/etc/init/" + filename
+ SetFileContents(filepath, Init_Ubuntu)
+ os.chmod(filepath, 0644)
+
+ else:
+ # Regular init.d configurations
+ filename = "waagent"
+ filepath = "/etc/init.d/" + filename
+
+ distro = IsRedHat() + IsDebian() * 2 + IsSuse()
+ if distro == 0:
+ Error("Unable to detect Linux Distribution.")
+ return 1
+ init = [[Init_RedHat, "chkconfig --add " + filename],
+ [Init_Debian, "update-rc.d " + filename + " defaults"],
+ [Init_Suse, "insserv " + filename]][distro - 1]
+ SetFileContents(filepath, init[0])
+ os.chmod(filepath, 0755)
+ Run(init[1])
+
if os.path.isfile("/etc/waagent.conf"):
try:
os.remove("/etc/waagent.conf.old")
@@ -2179,17 +2211,26 @@ def Uninstall():
Warn("Moved " + LibDir + "/" + GetLastPathElement(a) + " -> " + a )
except:
pass
+
+ filepath = "/etc/init.d/"
filename = "waagent"
- a = IsRedHat() + IsDebian() * 2 + IsSuse() * 3
- if a == 0:
- Error("Unable to detect Linux Distribution.")
- return 1
- Run("service " + filename + " stop")
- cmd = ["chkconfig --del " + filename,
- "update-rc.d -f " + filename + " remove",
- "insserv -r " + filename][a - 1]
- Run(cmd)
- for f in os.listdir(LibDir) + ["/etc/init.d/" + filename, "/etc/waagent.conf", "/etc/logrotate.d/waagent", "/etc/sudoers.d/waagent"]:
+
+ if IsUbuntu():
+ Run("stop " + filename)
+ filepath = "/etc/init/"
+ filename = "waagent.conf"
+ else:
+ a = IsRedHat() + IsDebian() * 2 + IsSuse() * 3
+ if a == 0:
+ Error("Unable to detect Linux Distribution.")
+ return 1
+ Run("service " + filename + " stop")
+ cmd = ["chkconfig --del " + filename,
+ "update-rc.d -f " + filename + " remove",
+ "insserv -r " + filename][a - 1]
+ Run(cmd)
+
+ for f in os.listdir(LibDir) + [filepath + filename, "/etc/waagent.conf", "/etc/logrotate.d/waagent", "/etc/sudoers.d/waagent"]:
try:
os.remove(f)
except:
@@ -2217,7 +2258,12 @@ def Deprovision(force, deluser):
print("WARNING! The waagent service will be stopped.")
print("WARNING! All SSH host key pairs will be deleted.")
- print("WARNING! Nameserver configuration in /etc/resolv.conf will be deleted.")
+
+ if IsUbuntu():
+ print("WARNING! Nameserver configuration in /etc/resolvconf/resolv.conf.d/{tail,originial} will be deleted.")
+ else:
+ print("WARNING! Nameserver configuration in /etc/resolv.conf will be deleted.")
+
print("WARNING! Cached DHCP leases will be deleted.")
delRootPass = Config.get("Provisioning.DeleteRootPassword")
@@ -2253,7 +2299,21 @@ def Deprovision(force, deluser):
Run("rm -f " + a + "/*")
# Clear LibDir, remove nameserver and root bash history
- for f in os.listdir(LibDir) + ["/etc/resolv.conf", "/root/.bash_history", "/var/log/waagent.log"]:
+ fileBlackList = [ "/root/.bash_history", "/var/log/waagent.log" ]
+
+ # Ubuntu uses resolvconf, so we want to preserve the ability to use resolvconf
+ if IsUbuntu():
+ if os.path.realpath('/etc/resolv.conf') != '/run/resolvconf/resolv.conf':
+ Log("resolvconf is not configured. Removing /etc/resolv.conf")
+ fileBlackList.append('/etc/resolv.conf')
+ else:
+ Log("resolvconf is enabled; leaving /etc/resolv.conf intact")
+ resolvConfD = '/etc/resolvconf/resolv.conf.d/'
+ fileBlackList.extend([resolvConfD + 'tail', resolvConfD + 'originial' ])
+ else:
+ fileBlackList.append(os.listdir(LibDir) + '/etc/resolv.conf')
+
+ for f in os.listdir(LibDir) + fileBlackList:
try:
os.remove(f)
except:
|