Merge "init: Add a way to class_restart only enabled services."
This commit is contained in:
commit
4993168f9c
2 changed files with 29 additions and 4 deletions
|
@ -496,8 +496,9 @@ Commands
|
|||
currently running, without disabling them. They can be restarted
|
||||
later using `class_start`.
|
||||
|
||||
`class_restart <serviceclass>`
|
||||
> Restarts all services of the specified class.
|
||||
`class_restart [--only-enabled] <serviceclass>`
|
||||
> Restarts all services of the specified class. If `--only-enabled` is
|
||||
specified, then disabled services are skipped.
|
||||
|
||||
`copy <src> <dst>`
|
||||
> Copies a file. Similar to write, but useful for binary/large
|
||||
|
|
|
@ -190,7 +190,31 @@ static Result<void> do_class_restart(const BuiltinArguments& args) {
|
|||
// Do not restart a class if it has a property persist.dont_start_class.CLASS set to 1.
|
||||
if (android::base::GetBoolProperty("persist.init.dont_start_class." + args[1], false))
|
||||
return {};
|
||||
ForEachServiceInClass(args[1], &Service::Restart);
|
||||
|
||||
std::string classname;
|
||||
|
||||
CHECK(args.size() == 2 || args.size() == 3);
|
||||
|
||||
bool only_enabled = false;
|
||||
if (args.size() == 3) {
|
||||
if (args[1] != "--only-enabled") {
|
||||
return Error() << "Unexpected argument: " << args[1];
|
||||
}
|
||||
only_enabled = true;
|
||||
classname = args[2];
|
||||
} else if (args.size() == 2) {
|
||||
classname = args[1];
|
||||
}
|
||||
|
||||
for (const auto& service : ServiceList::GetInstance()) {
|
||||
if (!service->classnames().count(classname)) {
|
||||
continue;
|
||||
}
|
||||
if (only_enabled && !service->IsEnabled()) {
|
||||
continue;
|
||||
}
|
||||
service->Restart();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -1392,7 +1416,7 @@ const BuiltinFunctionMap& GetBuiltinFunctionMap() {
|
|||
{"chmod", {2, 2, {true, do_chmod}}},
|
||||
{"chown", {2, 3, {true, do_chown}}},
|
||||
{"class_reset", {1, 1, {false, do_class_reset}}},
|
||||
{"class_restart", {1, 1, {false, do_class_restart}}},
|
||||
{"class_restart", {1, 2, {false, do_class_restart}}},
|
||||
{"class_start", {1, 1, {false, do_class_start}}},
|
||||
{"class_stop", {1, 1, {false, do_class_stop}}},
|
||||
{"copy", {2, 2, {true, do_copy}}},
|
||||
|
|
Loading…
Reference in a new issue