|
Line
Link Here
|
|
-- library/network/src/NetworkService.ycp |
|
|
|
Lines 27-34
you may find current contact information
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 |
*/ |
| 83 |
integer RunSystemCtl (string service, string action) { |
| 84 |
string cmd = sformat ("%1 %2 %3.service", systemctl, action, service); |
| 85 |
map<string,any> ret = (map<string,any>) SCR::Execute (.target.bash_output, cmd, $[ "TERM" : "raw"]); |
| 86 |
y2debug("RunSystemCtl: Command '%1' returned '%2'", cmd, ret); |
| 87 |
return ret["exit"]:-1; |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Whether a network service change were requested |
| 92 |
*/ |
| 93 |
global boolean Modified () { |
| 94 |
boolean ret = false; |
| 95 |
Read(); |
| 96 |
if (new_service_id_name != cur_service_id_name) |
| 97 |
{ |
| 98 |
ret = true; |
| 99 |
} |
| 100 |
y2debug("NetworkService::Modified(%1, %2) => %3", |
| 101 |
cur_service_id_name, new_service_id_name, ret); |
| 102 |
return ret; |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 53 |
* Whether use NetworkManager or ifup |
106 |
* Whether use NetworkManager or ifup |
| 54 |
*/ |
107 |
*/ |
| 55 |
global boolean IsManaged () { |
108 |
global boolean IsManaged () { |
| 56 |
Read (); |
109 |
Read (); |
| 57 |
return NetworkConfig::Config["NETWORKMANAGER"]:false; |
110 |
return new_service_id_name != "network"; |
| 58 |
|
|
|
| 59 |
} |
111 |
} |
| 60 |
|
112 |
|
| 61 |
/** |
113 |
/** |
| 62 |
* @param m whether networkmanager will be used |
114 |
* @param m whether networkmanager will be used |
| 63 |
*/ |
115 |
*/ |
| 64 |
global void SetManaged (boolean m) { |
116 |
global void SetManaged (boolean m) { |
| 65 |
NetworkConfig::Config["NETWORKMANAGER"] = m; |
117 |
Read (); |
| 66 |
initialized = true; |
118 |
new_service_id_name = m ? "NetworkManager" : "network"; |
| 67 |
} |
119 |
} |
| 68 |
|
120 |
|
| 69 |
/** |
121 |
/** |
|
Lines 72-79
global void SetManaged (boolean m) {
Link Here
|
| 72 |
global void Read () { |
124 |
global void Read () { |
| 73 |
if (!initialized) |
125 |
if (!initialized) |
| 74 |
{ |
126 |
{ |
| 75 |
NetworkConfig::Read (); |
127 |
cur_service_id_name = Service::GetServiceId("network"); |
| 76 |
boolean nm = NetworkConfig::Config["NETWORKMANAGER"]:false; |
128 |
new_service_id_name = cur_service_id_name; |
|
|
129 |
|
| 130 |
boolean nm = new_service_id_name != "network"; |
| 77 |
y2milestone ("NetworkManager: %1", nm); |
131 |
y2milestone ("NetworkManager: %1", nm); |
| 78 |
} |
132 |
} |
| 79 |
initialized = true; |
133 |
initialized = true; |
|
Lines 98-122
boolean RunScript (string script, string
Link Here
|
| 98 |
return SCR::Execute (.target.bash, cmd) == 0; |
152 |
return SCR::Execute (.target.bash, cmd) == 0; |
| 99 |
} |
153 |
} |
| 100 |
|
154 |
|
|
|
155 |
void EnableDisableNow() { |
| 156 |
if (Modified()) { |
| 157 |
/* Stop should be called before ... |
| 158 |
RunSystemCtl(cur_service_id_name, "kill"); |
| 159 |
*/ |
| 160 |
if (new_service_id_name == "network") { |
| 161 |
RunSystemCtl(cur_service_id_name, "disable"); |
| 162 |
} else { |
| 163 |
RunSystemCtl(new_service_id_name, "--force enable"); |
| 164 |
} |
| 165 |
cur_service_id_name = Service::GetServiceId("network"); |
| 166 |
new_service_id_name = cur_service_id_name; |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
/** |
| 171 |
* Reports if network _service_ is active or not. |
| 172 |
* It does not report if network is connected. |
| 173 |
*/ |
| 174 |
global boolean isActive() |
| 175 |
{ |
| 176 |
return RunSystemCtl ("network", "is-active") == 0; |
| 177 |
} |
| 178 |
|
| 101 |
/** |
179 |
/** |
| 102 |
* Starts and stops the appropriate services. |
180 |
* This is an old, confusing name for ReloadOrRestart() now |
| 103 |
*/ |
181 |
*/ |
| 104 |
global void StartStop () { |
182 |
global void StartStop () { |
| 105 |
if (Service::Status ("network") == 0) |
183 |
ReloadOrRestart(); |
| 106 |
{ |
184 |
} |
| 107 |
RunScript ("network", "reload"); |
185 |
|
| 108 |
} |
186 |
/** |
| 109 |
else |
187 |
* Reload or restars the network service. |
| 110 |
{ |
188 |
*/ |
|
|
189 |
global void ReloadOrRestart () { |
| 190 |
if (isActive()) { |
| 191 |
if (Modified()) { |
| 192 |
RunSystemCtl("network", "stop"); |
| 193 |
EnableDisableNow(); |
| 194 |
RunSystemCtl("network", "start"); |
| 195 |
} else { |
| 196 |
RunSystemCtl ("network", "reload-or-try-restart"); |
| 197 |
} |
| 198 |
} else { |
| 111 |
// #148263 |
199 |
// #148263 |
| 112 |
// Because rcnetwork really handles two different things in one script |
200 |
// Because rcnetwork really handles two different things in one script |
| 113 |
// (ifup and NM), it could happen that "start" would shut down an |
201 |
// (ifup and NM), it could happen that "start" would shut down an |
| 114 |
// interface. Instead, it tells the user to use "restart". |
202 |
// interface. Instead, it tells the user to use "restart". |
| 115 |
// So we do it always, it does not hurt if the net was stopped. |
203 |
// So we do it always, it does not hurt if the net was stopped. |
| 116 |
RunScript ("network", "restart"); |
204 |
RunSystemCtl("network", "stop"); |
|
|
205 |
EnableDisableNow(); |
| 206 |
RunSystemCtl("network", "start"); |
| 117 |
} |
207 |
} |
| 118 |
} |
208 |
} |
| 119 |
|
209 |
|
|
|
210 |
/** |
| 211 |
* Restarts the network service |
| 212 |
*/ |
| 213 |
global void Restart () { |
| 214 |
RunSystemCtl("network", "stop"); |
| 215 |
EnableDisableNow(); |
| 216 |
RunSystemCtl("network", "start"); |
| 217 |
} |
| 218 |
|
| 120 |
/* |
219 |
/* |
| 121 |
* Variable remembers that the question has been asked during this run already. |
220 |
* Variable remembers that the question has been asked during this run already. |
| 122 |
* It avoids useless questions over and over again. |
221 |
* It avoids useless questions over and over again. |
| 123 |
-- library/runlevel/src/Service.ycp |
|
|
|
Lines 123-128
define boolean checkExists (string name)
Link Here
|
| 123 |
} |
123 |
} |
| 124 |
|
124 |
|
| 125 |
/** |
125 |
/** |
|
|
126 |
* Get complete systemd unit id |
| 127 |
* @param name name or alias of the unit |
| 128 |
* @return (resolved) unit Id |
| 129 |
*/ |
| 130 |
global string GetUnitId(string unit) |
| 131 |
{ |
| 132 |
string cmd = sformat ("%1 --no-pager -p Id show %2", invoker, unit); |
| 133 |
map<string,any> ret = (map<string,any>) SCR::Execute (.target.bash_output, |
| 134 |
cmd, $[ "TERM" : "raw"]); |
| 135 |
if (ret["exit"]:-1 != 0) { |
| 136 |
y2error (_("Unable to query '%1' unit Id\nCommand returned: %2\n"), |
| 137 |
unit, ret); |
| 138 |
return nil; |
| 139 |
} |
| 140 |
|
| 141 |
/* extract first line */ |
| 142 |
integer end = findfirstof (ret["stdout"]:"", "\r\n"); |
| 143 |
string out = substring(ret["stdout"]:"", 0, end != nil ? end : 0); |
| 144 |
|
| 145 |
/* extract key anv value */ |
| 146 |
list tmp = splitstring (out, "="); |
| 147 |
if (size(tmp) != 2 || (tmp[0]:"") != "Id" || (tmp[1]:"") == "") { |
| 148 |
y2error (_("Unable to parse '%1' unit Id query output: '%2'\n"), |
| 149 |
unit, out); |
| 150 |
return nil; |
| 151 |
} |
| 152 |
|
| 153 |
return tmp[1]:""; |
| 154 |
} |
| 155 |
|
| 156 |
global string GetServiceId(string name) |
| 157 |
{ |
| 158 |
string id = GetUnitId(sformat("%1.service", name)); |
| 159 |
if (id == nil) |
| 160 |
return nil; |
| 161 |
|
| 162 |
/* return without .service */ |
| 163 |
integer pos = search(id, ".service"); |
| 164 |
if (pos <= 0) |
| 165 |
return nil; |
| 166 |
return substring(id, 0, pos); |
| 167 |
} |
| 168 |
|
| 169 |
/** |
| 126 |
* Get service info without peeking if service runs. |
170 |
* Get service info without peeking if service runs. |
| 127 |
* @param name name of the service |
171 |
* @param name name of the service |
| 128 |
* @return Service information or empty map ($[]) |
172 |
* @return Service information or empty map ($[]) |