Added a run_as string in json to configure which user the app has to be run by.
This commit is contained in:
parent
f75e4d236c
commit
7426d1dfd7
1 changed files with 38 additions and 5 deletions
15
main.cpp
15
main.cpp
|
|
@ -108,18 +108,19 @@ void printJsonHelp() {
|
|||
std::cout << "\t[REQUIRED] run_mode[string] : Mode can be daemon or script." << std::endl;
|
||||
std::cout << "\t\tMode daemon : The app forks the program and exits without waiting." << std::endl;
|
||||
std::cout << "\t\tMode script : The app forks the program and waits for it to finish execution." << std::endl;
|
||||
std::cout << "\t\tMode script : If no run_mode is given it is presumed to be script." << std::endl;
|
||||
std::cout << "\t\t If no run_mode is given it is presumed to be script." << std::endl;
|
||||
std::cout << "\t[OPTIONAL] after[{name,state}] : List containing names and state of modules." << std::endl;
|
||||
std::cout << "\t\tname[string] : Name of the other module." << std::endl;
|
||||
std::cout << "\t\tstate[string]: State of the other module." << std::endl;
|
||||
std::cout << "\t\t\t\tState exited : Specified module must have finished execution." << std::endl;
|
||||
std::cout << "\t\t\t\tState running : Specified module must be running." << std::endl;
|
||||
std::cout << "\t\t\tState exited : Specified module must have finished execution." << std::endl;
|
||||
std::cout << "\t\t\tState running : Specified module must be running." << std::endl;
|
||||
std::cout << "\t\tThis module will be launched after the module found\n\t\t"
|
||||
"in this list using name is at the state specified as state." << std::endl;
|
||||
std::cout << "\t[OPTIONAL] env{} : Additional enviroment variables." << std::endl;
|
||||
std::cout << "\t\tEvery key in this object will be used as environment name,\n\t\tand every corresponding value as its value." << std::endl;
|
||||
std::cout << "\t[OPTIONAL] working_dir[string] : Working directory of the program." << std::endl;
|
||||
std::cout << "\t[OPTIONAL] create_log[boolean] : Create a log file at logs path." << std::endl;
|
||||
std::cout << "\t[OPTIONAL] run_as[string] : Run as a particular user." << std::endl;
|
||||
std::cout << std::endl << "Example startup_apps.json: ";
|
||||
std::cout << R"(
|
||||
[
|
||||
|
|
@ -138,8 +139,9 @@ void printJsonHelp() {
|
|||
"run_mode": "script",
|
||||
"create_log": true,
|
||||
"after": [{"module": "LS 0", "state": "exited"}],
|
||||
"env": {"PATH": "/home/:/usr/bin/", "NAME": "ONE"}
|
||||
"working_dir": "/home/etc"
|
||||
"env": {"PATH": "/home/:/usr/bin/", "NAME": "ONE"},
|
||||
"working_dir": "/home/etc",
|
||||
"run_as": "username"
|
||||
}
|
||||
]
|
||||
)" << std::endl;
|
||||
|
|
@ -506,6 +508,8 @@ int main(int argc, char *argv[]) {
|
|||
app_info.working_dir = object["working_dir"].get<std::string>();
|
||||
if(object.find("create_log") != object.end())
|
||||
app_info.create_log = object["create_log"].get<bool>();
|
||||
if(object.find("run_as") != object.end())
|
||||
app_info.run_as = object["run_as"].get<std::string>();
|
||||
app_info.env = env_list;
|
||||
app_info.after = after_list;
|
||||
app_info.module_name = object["name"].get<std::string>();
|
||||
|
|
@ -514,6 +518,7 @@ int main(int argc, char *argv[]) {
|
|||
initial_app_list.push_back(app_info);
|
||||
}
|
||||
std::vector<std::shared_ptr<AppInfo>> list;
|
||||
log_file << "Checking App List for errors." << std::endl;
|
||||
auto list_check = checkAppList(initial_app_list, list, log_file.rdbuf());
|
||||
if(list_check.has_value()) {
|
||||
log_file << "No errors found in app list." << std::endl;
|
||||
|
|
|
|||
Loading…
Reference in a new issue