34 #include <sys/types.h>
51 const std::string& commandLineParameters)
53 if (application->getPid() != -1 || application->getStatusWriteBlock())
55 return std::future<void>();
58 application->setStatusWriteBlock(
true);
60 getStarter(application->getScenario()).get(),
63 commandLineParameters,
66 std::future<void> result = task.get_future();
67 std::thread t(std::move(task));
82 if (application->getStatusWriteBlock())
84 return std::future<void>();
87 application->setStatusWriteBlock(
true);
89 getStopStrategy(application->getScenario()).get(),
91 std::future<void> result = task.get_future();
92 std::thread(std::move(task)).detach();
101 getStopStrategy(scenario)->stop(application);
104 auto state = getStarter(scenario)->getStatus(application, statusManager);
108 std::this_thread::sleep_for(std::chrono::milliseconds(100));
111 if (waitCount == 200)
113 ARMARX_INFO_S <<
"The application " << application->getName()
114 <<
" is not Stopping please force kill it or try again. Aborting restart";
117 state = getStarter(scenario)->getStatus(application, statusManager);
120 ARMARX_INFO <<
"Starting application `" << application->getName() <<
"` which is `"
121 << application->getExecutableAbsPath() <<
"`";
122 getStarter(scenario)->startApplication(application, statusManager,
"", printOnly);
128 if (application->getStatusWriteBlock())
130 return std::future<void>();
133 application->setStatusWriteBlock(
true);
135 std::packaged_task<void()> task(std::bind(
136 &Executor::asyncApplicationRestart,
this, application, printOnly));
138 std::future<void> result = task.get_future();
139 std::thread(std::move(task)).detach();
147 if (application->getStatusWriteBlock())
151 return getStarter(application->getScenario())->getStatus(application, statusManager);
157 const std::string& commandLineParameters)
159 if (scenario->getStatusWriteBlock())
161 return std::future<void>();
164 scenario->setStatusWriteBlock(
true);
166 getStarter(scenario).get(),
169 commandLineParameters,
172 std::future<void> result = task.get_future();
173 std::thread t(std::move(task));
188 std::vector<std::future<void>> futures;
190 std::vector<ApplicationInstancePtr> apps = *scenario->getApplications();
191 for (
auto it = apps.begin(); it != apps.end(); it++)
193 futures.push_back(stopApplication(*it));
196 for (
auto future = futures.begin(); future != futures.end(); ++future)
205 std::packaged_task<void()> task(
206 std::bind(&Executor::asyncScenarioStop,
this, scenario));
207 std::future<void> result = task.get_future();
208 std::thread(std::move(task)).detach();
216 std::vector<std::future<void>> futures;
217 for (
auto app : *scenario->getApplications())
219 futures.push_back(restartApplication(app, printOnly));
222 for (
auto future = futures.begin(); future != futures.end(); ++future)
231 std::packaged_task<void()> task(
232 std::bind(&Executor::asyncScenarioRestart,
this, scenario, printOnly));
233 std::future<void> result = task.get_future();
234 std::thread(std::move(task)).detach();
245 std::filesystem::path xmlFilePath =
246 std::filesystem::path(path) / std::filesystem::path(application->getPackageName() +
"." +
247 application->getName() +
".xml");
249 if (reload || !std::filesystem::exists(xmlFilePath))
251 std::filesystem::create_directories(path);
253 std::string strCommand = application->getExecutableAbsPath()
254 .append(
" -p -f xml -o ")
255 .append(xmlFilePath.string());
256 int ret = system(strCommand.c_str());
259 ARMARX_WARNING <<
"Failed to generate properties xml for " << application->getName()
260 <<
"\nCommand was: " << strCommand;
265 application->updateFound();
266 if (!application->getFound())
271 auto xmlDate = (std::filesystem::last_write_time(xmlFilePath));
274 std::filesystem::last_write_time(application->getPathToExecutable().append(
"/").append(
275 application->getExecutableName()));
277 if (execDate > xmlDate)
279 loadAndSetCachedProperties(application, path,
true,
set);
287 application->setProperties(
parser.loadFromXml(xmlFilePath.string()));
294 defaultStopStrategy = strategy;
300 defaultStartStrategy = appStarter;
306 this->stopStrategy[scenario] = strategy;
312 this->starter[scenario] = appStarter;
318 if (starter.count(scenario) == 0)
320 return defaultStartStrategy;
322 return starter[scenario];
328 if (stopStrategy.count(scenario) == 0)
330 return defaultStopStrategy;
332 return stopStrategy[scenario];
338 return defaultStopStrategy;