|
Lines 27-34
you may find current contact information at www.novell.com
Link Here
|
| 27 |
* |
27 |
* |
| 28 |
* $Id$ |
28 |
* $Id$ |
| 29 |
* |
29 |
* |
| 30 |
* This module used to switch between rcnetwork and rcnetworkmanager. |
30 |
* This module used to switch between /etc/init.d/network providing |
| 31 |
* Now the master switch is /etc/sysconfig/network/config:NETWORKMANAGER |
31 |
* LSB network.service and the NetworkManager.service (or another), |
|
|
32 |
* which installs a network.service alias link. |
| 33 |
* |
| 34 |
* The service name installing the network.sevice is visible in the |
| 35 |
* "Id" systemctl property: |
| 36 |
* |
| 37 |
* # systemctl --no-pager -p Id show network.service |
| 38 |
* Id=network.service |
| 39 |
* # systemctl --force enable NetworkManager.service |
| 40 |
* # systemctl --no-pager -p Id show network.service |
| 41 |
* Id=NetworkManager.service |
| 42 |
* |
| 43 |
* The network.service alias link obsoletes the old master switch in |
| 44 |
* /etc/sysconfig/network/config:NETWORKMANAGER (until openSUSE-12.2). |
| 32 |
*/ |
45 |
*/ |
| 33 |
|
46 |
|
| 34 |
{ |
47 |
{ |
|
Lines 50-69
global void Read ();
Link Here
|
| 50 |
boolean initialized = false; |
63 |
boolean initialized = false; |
| 51 |
|
64 |
|
| 52 |
/** |
65 |
/** |
|
|
66 |
* current network service id name |
| 67 |
*/ |
| 68 |
string cur_service_id_name = ""; |
| 69 |
|
| 70 |
/** |
| 71 |
* the new network service id name |
| 72 |
*/ |
| 73 |
string new_service_id_name = ""; |
| 74 |
|
| 75 |
/** |
| 76 |
* Path to the systemctl command |
| 77 |
*/ |
| 78 |
string systemctl = "/bin/systemctl"; |
| 79 |
|
| 80 |
/** |
| 81 |
* Helper to run systemctl actions |
| 82 |
* @return exit code |
| 83 |
*/ |
| 84 |
integer RunSystemCtl (string service, string action) { |
| 85 |
string cmd = sformat ("%1 %2 %3.service", systemctl, action, service); |
| 86 |
map<string,any> ret = (map<string,any>) SCR::Execute (.target.bash_output, cmd, $[ "TERM" : "raw"]); |
| 87 |
y2debug("RunSystemCtl: Command '%1' returned '%2'", cmd, ret); |
| 88 |
return ret["exit"]:-1; |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Whether a network service change were requested |
| 93 |
* @return true when service change were requested |
| 94 |
*/ |
| 95 |
global boolean Modified () { |
| 96 |
boolean ret = false; |
| 97 |
Read(); |
| 98 |
if (new_service_id_name != cur_service_id_name) { |
| 99 |
ret = true; |
| 100 |
} |
| 101 |
y2debug("NetworkService::Modified(%1, %2) => %3", |
| 102 |
cur_service_id_name, new_service_id_name, ret); |
| 103 |
return ret; |
| 104 |
} |
| 105 |
|
| 106 |
/** |
| 53 |
* Whether use NetworkManager or ifup |
107 |
* Whether use NetworkManager or ifup |
|
|
108 |
* @return true when the network is managed, false when |
| 109 |
* the /etc/init.d/network script is in use. |
| 54 |
*/ |
110 |
*/ |
| 55 |
global boolean IsManaged () { |
111 |
global boolean IsManaged () { |
| 56 |
Read (); |
112 |
Read (); |
| 57 |
return NetworkConfig::Config["NETWORKMANAGER"]:false; |
113 |
return new_service_id_name != "network"; |
| 58 |
|
|
|
| 59 |
} |
114 |
} |
| 60 |
|
115 |
|
| 61 |
/** |
116 |
/** |
| 62 |
* @param m whether networkmanager will be used |
117 |
* @param m whether networkmanager will be used |
| 63 |
*/ |
118 |
*/ |
| 64 |
global void SetManaged (boolean m) { |
119 |
global void SetManaged (boolean m) { |
| 65 |
NetworkConfig::Config["NETWORKMANAGER"] = m; |
120 |
Read (); |
| 66 |
initialized = true; |
121 |
new_service_id_name = m ? "NetworkManager" : "network"; |
| 67 |
} |
122 |
} |
| 68 |
|
123 |
|
| 69 |
/** |
124 |
/** |
|
Lines 72-79
global void SetManaged (boolean m) {
Link Here
|
| 72 |
global void Read () { |
127 |
global void Read () { |
| 73 |
if (!initialized) |
128 |
if (!initialized) |
| 74 |
{ |
129 |
{ |
| 75 |
NetworkConfig::Read (); |
130 |
cur_service_id_name = Service::GetServiceId("network"); |
| 76 |
boolean nm = NetworkConfig::Config["NETWORKMANAGER"]:false; |
131 |
new_service_id_name = cur_service_id_name; |
|
|
132 |
|
| 133 |
boolean nm = new_service_id_name != "network"; |
| 77 |
y2milestone ("NetworkManager: %1", nm); |
134 |
y2milestone ("NetworkManager: %1", nm); |
| 78 |
} |
135 |
} |
| 79 |
initialized = true; |
136 |
initialized = true; |
|
Lines 89-94
global void EnableDisable () {
Link Here
|
| 89 |
SCR::Execute (.target.bash, cmd); |
146 |
SCR::Execute (.target.bash, cmd); |
| 90 |
} |
147 |
} |
| 91 |
|
148 |
|
|
|
149 |
/* |
| 150 |
* Run /etc/init.d script with specified action |
| 151 |
* @param script name of the init script |
| 152 |
* @param action the action to use |
| 153 |
* @return true, when the script exits with 0 |
| 154 |
*/ |
| 92 |
boolean RunScript (string script, string action) { |
155 |
boolean RunScript (string script, string action) { |
| 93 |
if (script == "") |
156 |
if (script == "") |
| 94 |
return true; |
157 |
return true; |
|
Lines 98-122
boolean RunScript (string script, string action) {
Link Here
|
| 98 |
return SCR::Execute (.target.bash, cmd) == 0; |
161 |
return SCR::Execute (.target.bash, cmd) == 0; |
| 99 |
} |
162 |
} |
| 100 |
|
163 |
|
| 101 |
/** |
164 |
/* |
| 102 |
* Starts and stops the appropriate services. |
165 |
* Helper to apply a change of the network service |
| 103 |
*/ |
166 |
*/ |
| 104 |
global void StartStop () { |
167 |
void EnableDisableNow() { |
| 105 |
if (Service::Status ("network") == 0) |
168 |
if (Modified()) { |
| 106 |
{ |
169 |
/* Stop should be called before, but when the service |
| 107 |
RunScript ("network", "reload"); |
170 |
* were not correctly started until now, stop may have |
|
|
171 |
* no effect. |
| 172 |
* So let's kill all processes in the network service |
| 173 |
* cgroup to make sure e.g. dhcp clients are stopped. |
| 174 |
*/ |
| 175 |
RunSystemCtl(cur_service_id_name, "kill"); |
| 176 |
|
| 177 |
if (new_service_id_name == "network") { |
| 178 |
RunSystemCtl(cur_service_id_name, "disable"); |
| 179 |
} else { |
| 180 |
RunSystemCtl(new_service_id_name, "--force enable"); |
| 181 |
} |
| 182 |
cur_service_id_name = Service::GetServiceId("network"); |
| 183 |
new_service_id_name = cur_service_id_name; |
| 108 |
} |
184 |
} |
| 109 |
else |
185 |
} |
| 110 |
{ |
186 |
|
| 111 |
// #148263 |
187 |
/** |
| 112 |
// Because rcnetwork really handles two different things in one script |
188 |
* Reports if network service is active or not. |
| 113 |
// (ifup and NM), it could happen that "start" would shut down an |
189 |
* It does not report if network is connected. |
| 114 |
// interface. Instead, it tells the user to use "restart". |
190 |
* @return true when network service is active |
| 115 |
// So we do it always, it does not hurt if the net was stopped. |
191 |
*/ |
| 116 |
RunScript ("network", "restart"); |
192 |
global boolean IsActive() |
|
|
193 |
{ |
| 194 |
return RunSystemCtl ("network", "is-active") == 0; |
| 195 |
} |
| 196 |
|
| 197 |
/** |
| 198 |
* Reload or restars the network service. |
| 199 |
*/ |
| 200 |
global void ReloadOrRestart () { |
| 201 |
if (IsActive()) { |
| 202 |
if (Modified()) { |
| 203 |
// reload is not sufficient |
| 204 |
RunSystemCtl("network", "stop"); |
| 205 |
EnableDisableNow(); |
| 206 |
RunSystemCtl("network", "start"); |
| 207 |
} else { |
| 208 |
// reload may be unsupported |
| 209 |
RunSystemCtl ("network", "reload-or-try-restart"); |
| 210 |
} |
| 211 |
} else { |
| 212 |
// always stop, it does not hurt if the net was stopped. |
| 213 |
RunSystemCtl("network", "stop"); |
| 214 |
EnableDisableNow(); |
| 215 |
RunSystemCtl("network", "start"); |
| 117 |
} |
216 |
} |
| 118 |
} |
217 |
} |
| 119 |
|
218 |
|
|
|
219 |
/** |
| 220 |
* Restarts the network service |
| 221 |
*/ |
| 222 |
global void Restart () { |
| 223 |
RunSystemCtl("network", "stop"); |
| 224 |
EnableDisableNow(); |
| 225 |
RunSystemCtl("network", "start"); |
| 226 |
} |
| 227 |
|
| 228 |
/** |
| 229 |
* This is an old, confusing name for ReloadOrRestart() now |
| 230 |
*/ |
| 231 |
global void StartStop () { |
| 232 |
ReloadOrRestart(); |
| 233 |
} |
| 234 |
|
| 120 |
/* |
235 |
/* |
| 121 |
* Variable remembers that the question has been asked during this run already. |
236 |
* Variable remembers that the question has been asked during this run already. |
| 122 |
* It avoids useless questions over and over again. |
237 |
* It avoids useless questions over and over again. |