| 340 | ; |
| 341 | |
| 342 | string |
| 343 | writeScript(const string &ckptDir, |
| 344 | bool uniqueCkptFilenames, |
| 345 | const time_t &ckptTimeStamp, |
| 346 | const uint32_t theCheckpointInterval, |
| 347 | const int thePort, |
| 348 | const UniquePid &compId, |
| 349 | const map<string, vector<string> > &restartFilenames, |
| 350 | const map<string, vector<string> >& rshCmdFileNames, |
| 351 | const map<string, vector<string> >& sshCmdFileNames) |
| 352 | { |
| 353 | ostringstream o; |
| 354 | string uniqueFilename; |
| 355 | |
| 356 | o << string(ckptDir) << "/" |
| 357 | << RESTART_SCRIPT_BASENAME << "_" << compId; |
| 358 | if (uniqueCkptFilenames) { |
| 359 | o << "_" << std::setw(5) << std::setfill('0') << |
| 360 | compId.computationGeneration(); |
| 361 | } |
| 362 | o << "." << RESTART_SCRIPT_EXT; |
| 363 | uniqueFilename = o.str(); |
| 364 | |
| 365 | const bool isSingleHost = ((rshCmdFileNames.size() == 0) && (sshCmdFileNames.size() == 0) && (restartFilenames.size() == 1)); |
| 366 | |
| 367 | map<string, vector<string> >::const_iterator host; |
| 368 | |
| 369 | size_t numPeers = 0; |
| 370 | for (host = restartFilenames.begin(); |
| 371 | host != restartFilenames.end(); |
| 372 | host++) { |
| 373 | numPeers += host->second.size(); |
| 374 | } |
| 375 | for (host = rshCmdFileNames.begin(); |
| 376 | host != rshCmdFileNames.end(); |
| 377 | host++) { |
| 378 | numPeers += host->second.size(); |
| 379 | } |
| 380 | for (host = sshCmdFileNames.begin(); |
| 381 | host != sshCmdFileNames.end(); |
| 382 | host++) { |
| 383 | numPeers += host->second.size(); |
| 384 | } |
| 385 | |
| 386 | |
| 387 | vector<string>::const_iterator file; |
| 388 | |
| 389 | char hostname[80]; |
| 390 | char timestamp[80]; |
| 391 | gethostname(hostname, 80); |
| 392 | |
| 393 | JTRACE("writing restart script") (uniqueFilename); |
| 394 | |
| 395 | FILE *fp = fopen(uniqueFilename.c_str(), "w"); |
| 396 | JASSERT(fp != 0)(JASSERT_ERRNO)(uniqueFilename) |
| 397 | .Text("failed to open file"); |
| 398 | |
| 399 | fprintf(fp, "%s", header); |