If you need activate or de-activate services from your yast2 package, use module Service. It is a replacement for the old client runlevel_adjust that you should have been using till now. You may also use it to obtain information about services. Following functions are self-containing. You do not need to run Service::Read if you want to use any of them.
boolean Service::Adjust (string name, string action);
Does some operation with init script. name is the name of the init
script. action is one of: "enable", "disable",
"default".
boolean Service::Finetune (string name, list rl);
Sets service to run in list rl. rl is list of strings.
example: Service::Finetune ("cups", [ "5" ]);
example: Service::Finetune ("cups", [ "S", "3", "5" ]);
integer RunInitScript (string name, string param);
Runs init script name with parameter param. Returns init
scripts exit value. I do not think it is worth to import module
Service only because of this one function when you may simply call
SCR::Execute (.target.bash, ...) with the same result. But if you use
Service for something else, this function may increase readability of the
code.
example: RunInitScript ("cups", "restart");
integer Service::Status (string name)
map Service::Info (string name)
map Service::FullInfo (string name)
Service::Status tells whether service runs. It calls init script status
and returns exit value.
Service::Info returns information about
service. The map contains:
$[ "defstart" : [ ... ], // list of strings "defstop" : [ ... ], // list of default runlevels "start" : [ ... ], // list of strings "stop" : [ ... ], // list of real runlevels "reqstart" : [ ... ], // list of strings "reqstop" : [ ... ], // prerequisites "description": string,// description ]Values "def{start|stop}", "req{start|stop}" and "description" are taken from init script comments. "start" and "stop" are taken from links. Service::FullInfo combines info from Service::Info and Service::Status into one map. It adds key "started" with integeral value of script status. Service is enabled if "start" is not empty.
boolean Service::Enabled (string name)
Returns true if service is set to run in any runlevel. False otherwise.
import "Service"; boolean Read () ``{ if (0 != Service::RunInitScript ("foo", "restart")) { y2error ("Can not start service"); return false; } // ... your code ... } boolean Write () ``{ // ... write settings ... // set service to correct state if (start_it) { // enable service Service::Adjust ("foo", "enable"); // reload changed settings Service::RunInitScript ("foo", "reload"); } else { // disable service Service::Adjust ("foo", "disable"); // and stop it Service::RunInitScript ("foo", "stop"); } }
Can be found here.