Bugzilla – Attachment 521559 Details for
Bug 798348
No network without networkmanager
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Forgot Password
[patch]
yast2-2.23.19: merged prototype patch to use network.service instead NETWORKMANAGER
yast2-2.23.19.diff (text/plain), 8.46 KB, created by
Marius Tomaschewski
on 2013-01-23 12:06:26 UTC
(
hide
)
Description:
yast2-2.23.19: merged prototype patch to use network.service instead NETWORKMANAGER
Filename:
MIME Type:
Creator:
Marius Tomaschewski
Created:
2013-01-23 12:06:26 UTC
Size:
8.46 KB
patch
obsolete
>From 1b46a6f602a8b74d24b07b5cd96841b9ad4442cd Mon Sep 17 00:00:00 2001 >From: Marius Tomaschewski <mt@suse.de> >Date: Wed, 23 Jan 2013 11:47:15 +0100 >Subject: [PATCH] Prototype: Changed to use network.service alias > >Changed to use network.service alias installed by the NetworkManager >service file while "systemctl enable". >Obsoletes the use of the NETWORKMANAGER=yes/no sysconfig variable in >/etc/sysconfig/network/config (bnc#764055,bnc#764336,bnc#798348). >--- > library/network/src/NetworkService.ycp | 159 +++++++++++++++++++++++++++----- > library/runlevel/src/Service.ycp | 49 ++++++++++ > 2 Dateien geändert, 186 Zeilen hinzugefügt(+), 22 Zeilen entfernt(-) > >diff --git a/library/network/src/NetworkService.ycp b/library/network/src/NetworkService.ycp >index 8ec646d..d92bc60 100644 >--- a/library/network/src/NetworkService.ycp >+++ b/library/network/src/NetworkService.ycp >@@ -27,8 +27,21 @@ you may find current contact information at www.novell.com > * > * $Id$ > * >- * This module used to switch between rcnetwork and rcnetworkmanager. >- * Now the master switch is /etc/sysconfig/network/config:NETWORKMANAGER >+ * This module used to switch between /etc/init.d/network providing >+ * LSB network.service and the NetworkManager.service (or another), >+ * which installs a network.service alias link. >+ * >+ * The service name installing the network.sevice is visible in the >+ * "Id" systemctl property: >+ * >+ * # systemctl --no-pager -p Id show network.service >+ * Id=network.service >+ * # systemctl --force enable NetworkManager.service >+ * # systemctl --no-pager -p Id show network.service >+ * Id=NetworkManager.service >+ * >+ * The network.service alias link obsoletes the old master switch in >+ * /etc/sysconfig/network/config:NETWORKMANAGER (until openSUSE-12.2). > */ > > { >@@ -50,20 +63,62 @@ global void Read (); > boolean initialized = false; > > /** >+ * current network service id name >+ */ >+string cur_service_id_name = ""; >+ >+/** >+ * the new network service id name >+ */ >+string new_service_id_name = ""; >+ >+/** >+ * Path to the systemctl command >+ */ >+string systemctl = "/bin/systemctl"; >+ >+/** >+ * Helper to run systemctl actions >+ * @return exit code >+ */ >+integer RunSystemCtl (string service, string action) { >+ string cmd = sformat ("%1 %2 %3.service", systemctl, action, service); >+ map<string,any> ret = (map<string,any>) SCR::Execute (.target.bash_output, cmd, $[ "TERM" : "raw"]); >+ y2debug("RunSystemCtl: Command '%1' returned '%2'", cmd, ret); >+ return ret["exit"]:-1; >+} >+ >+/** >+ * Whether a network service change were requested >+ * @return true when service change were requested >+ */ >+global boolean Modified () { >+ boolean ret = false; >+ Read(); >+ if (new_service_id_name != cur_service_id_name) { >+ ret = true; >+ } >+ y2debug("NetworkService::Modified(%1, %2) => %3", >+ cur_service_id_name, new_service_id_name, ret); >+ return ret; >+} >+ >+/** > * Whether use NetworkManager or ifup >+ * @return true when the network is managed, false when >+ * the /etc/init.d/network script is in use. > */ > global boolean IsManaged () { > Read (); >- return NetworkConfig::Config["NETWORKMANAGER"]:false; >- >+ return new_service_id_name != "network"; > } > > /** > * @param m whether networkmanager will be used > */ > global void SetManaged (boolean m) { >- NetworkConfig::Config["NETWORKMANAGER"] = m; >- initialized = true; >+ Read (); >+ new_service_id_name = m ? "NetworkManager" : "network"; > } > > /** >@@ -72,8 +127,10 @@ global void SetManaged (boolean m) { > global void Read () { > if (!initialized) > { >- NetworkConfig::Read (); >- boolean nm = NetworkConfig::Config["NETWORKMANAGER"]:false; >+ cur_service_id_name = Service::GetServiceId("network"); >+ new_service_id_name = cur_service_id_name; >+ >+ boolean nm = new_service_id_name != "network"; > y2milestone ("NetworkManager: %1", nm); > } > initialized = true; >@@ -89,6 +146,12 @@ global void EnableDisable () { > SCR::Execute (.target.bash, cmd); > } > >+/* >+ * Run /etc/init.d script with specified action >+ * @param script name of the init script >+ * @param action the action to use >+ * @return true, when the script exits with 0 >+ */ > boolean RunScript (string script, string action) { > if (script == "") > return true; >@@ -98,25 +161,77 @@ boolean RunScript (string script, string action) { > return SCR::Execute (.target.bash, cmd) == 0; > } > >-/** >- * Starts and stops the appropriate services. >+/* >+ * Helper to apply a change of the network service > */ >-global void StartStop () { >- if (Service::Status ("network") == 0) >- { >- RunScript ("network", "reload"); >+void EnableDisableNow() { >+ if (Modified()) { >+ /* Stop should be called before, but when the service >+ * were not correctly started until now, stop may have >+ * no effect. >+ * So let's kill all processes in the network service >+ * cgroup to make sure e.g. dhcp clients are stopped. >+ */ >+ RunSystemCtl(cur_service_id_name, "kill"); >+ >+ if (new_service_id_name == "network") { >+ RunSystemCtl(cur_service_id_name, "disable"); >+ } else { >+ RunSystemCtl(new_service_id_name, "--force enable"); >+ } >+ cur_service_id_name = Service::GetServiceId("network"); >+ new_service_id_name = cur_service_id_name; > } >- else >- { >- // #148263 >- // Because rcnetwork really handles two different things in one script >- // (ifup and NM), it could happen that "start" would shut down an >- // interface. Instead, it tells the user to use "restart". >- // So we do it always, it does not hurt if the net was stopped. >- RunScript ("network", "restart"); >+} >+ >+/** >+ * Reports if network service is active or not. >+ * It does not report if network is connected. >+ * @return true when network service is active >+ */ >+global boolean IsActive() >+{ >+ return RunSystemCtl ("network", "is-active") == 0; >+} >+ >+/** >+ * Reload or restars the network service. >+ */ >+global void ReloadOrRestart () { >+ if (IsActive()) { >+ if (Modified()) { >+ // reload is not sufficient >+ RunSystemCtl("network", "stop"); >+ EnableDisableNow(); >+ RunSystemCtl("network", "start"); >+ } else { >+ // reload may be unsupported >+ RunSystemCtl ("network", "reload-or-try-restart"); >+ } >+ } else { >+ // always stop, it does not hurt if the net was stopped. >+ RunSystemCtl("network", "stop"); >+ EnableDisableNow(); >+ RunSystemCtl("network", "start"); > } > } > >+/** >+ * Restarts the network service >+ */ >+global void Restart () { >+ RunSystemCtl("network", "stop"); >+ EnableDisableNow(); >+ RunSystemCtl("network", "start"); >+} >+ >+/** >+ * This is an old, confusing name for ReloadOrRestart() now >+ */ >+global void StartStop () { >+ ReloadOrRestart(); >+} >+ > /* > * Variable remembers that the question has been asked during this run already. > * It avoids useless questions over and over again. >diff --git a/library/runlevel/src/Service.ycp b/library/runlevel/src/Service.ycp >index accc922..e460dbb 100644 >--- a/library/runlevel/src/Service.ycp >+++ b/library/runlevel/src/Service.ycp >@@ -136,6 +136,55 @@ define boolean checkExists (string name) { > } > > /** >+ * Get complete systemd unit id >+ * @param name name or alias of the unit >+ * @return (resolved) unit Id >+ */ >+global string GetUnitId(string unit) >+{ >+ string cmd = sformat ("%1 --no-pager -p Id show %2", invoker, unit); >+ map<string,any> ret = (map<string,any>) SCR::Execute (.target.bash_output, >+ cmd, $[ "TERM" : "raw"]); >+ if (ret["exit"]:-1 != 0) { >+ y2error (_("Unable to query '%1' unit Id\nCommand returned: %2\n"), >+ unit, ret); >+ return nil; >+ } >+ >+ /* extract first line */ >+ integer end = findfirstof (ret["stdout"]:"", "\r\n"); >+ string out = substring(ret["stdout"]:"", 0, end != nil ? end : 0); >+ >+ /* extract key anv value */ >+ list tmp = splitstring (out, "="); >+ if (size(tmp) != 2 || (tmp[0]:"") != "Id" || (tmp[1]:"") == "") { >+ y2error (_("Unable to parse '%1' unit Id query output: '%2'\n"), >+ unit, out); >+ return nil; >+ } >+ >+ return tmp[1]:""; >+} >+ >+/** >+ * Get the name from a systemd service unit id without the .service suffix >+ * @param name name or alias of the service >+ * @return (resolved) service name without the .service suffix >+ */ >+global string GetServiceId(string name) >+{ >+ string id = GetUnitId(sformat("%1.service", name)); >+ if (id == nil) >+ return nil; >+ >+ /* return without .service */ >+ integer pos = search(id, ".service"); >+ if (pos <= 0) >+ return nil; >+ return substring(id, 0, pos); >+} >+ >+/** > * Get service info without peeking if service runs. > * @param name name of the service > * @return Service information or empty map ($[]) >-- >1.7.10.4 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
Actions:
View
|
Diff
Attachments on
bug 798348
:
520129
|
520659
|
520661
|
520665
|
520666
| 521559 |
521560
|
528381