Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respawn all option #8

Merged
merged 10 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions rosmon_core/src/launch/launch_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ void LaunchConfig::setDefaultMemoryLimit(uint64_t memoryLimit)
m_defaultMemoryLimit = memoryLimit;
}

void LaunchConfig::setRespawnBehaviour(bool respawnAll, bool respawnObey)
{
m_respawnAll = respawnAll;
m_respawnObey = respawnObey;
}

void LaunchConfig::parse(const std::string& filename, bool onlyArguments)
{
m_rootContext.setFilename(filename);
Expand Down Expand Up @@ -381,10 +387,16 @@ void LaunchConfig::parseNode(TiXmlElement* element, ParseContext ctx)
if(!fullNamespace.empty())
node->setNamespace(fullNamespace);

if(respawn)
if ((m_respawnObey && respawn) || !m_respawnObey)
{
node->setRespawn(ctx.parseBool(respawn, element->Row()));

if (!m_respawnObey)
{
node->setRespawn(m_respawnAll);
}
else
{
node->setRespawn(ctx.parseBool(respawn, element->Row()));
}
if(respawnDelay)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you verified this is not an issue?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, respawndelay is only used if respawn is set.

{
double seconds;
Expand Down
8 changes: 6 additions & 2 deletions rosmon_core/src/launch/launch_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ class LaunchConfig
void setArgument(const std::string& name, const std::string& value);

void setDefaultStopTimeout(double timeout);
void setDefaultCPULimit(double CPULimit);
void setDefaultMemoryLimit(uint64_t memoryLimit);
void setDefaultCPULimit(double CPULimit);
void setDefaultMemoryLimit(uint64_t memoryLimit);
void setRespawnBehaviour(bool respawnAll, bool respawnObey);

void parse(const std::string& filename, bool onlyArguments = false);
void parseString(const std::string& input, bool onlyArguments = false);
Expand Down Expand Up @@ -237,6 +238,9 @@ class LaunchConfig
double m_defaultStopTimeout{DEFAULT_STOP_TIMEOUT};
uint64_t m_defaultMemoryLimit{DEFAULT_MEMORY_LIMIT};
double m_defaultCPULimit{DEFAULT_CPU_LIMIT};

bool m_respawnAll;
bool m_respawnObey;
};

}
Expand Down
19 changes: 19 additions & 0 deletions rosmon_core/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ void usage()
" Use GROUP as name of the launch group. By default, empty\n"
" --launch-config=CONFIG\n"
" Use CONFIG as name of the launch config. By default, empty\n"
" --respawn-attr=obey|force_true|force_false\n"
" Force all nodes in launch group to respawn or not respawn,\n"
" or obey launch file. By default, nodes will obey.\n"
" --no-start Don't automatically start the nodes in the beginning\n"
" --stop-timeout=SECONDS\n"
" Kill a process if it is still running this long\n"
Expand Down Expand Up @@ -133,6 +136,7 @@ static const struct option OPTIONS[] = {
{"robot", required_argument, nullptr, 'r'},
{"launch-group", required_argument, nullptr, 'g'},
{"launch-config", required_argument, nullptr, 'z'},
{"respawn-attr", required_argument, nullptr, 'R'},
{"no-start", no_argument, nullptr, 'S'},
{"stop-timeout", required_argument, nullptr, 's'},
{"disable-diagnostics", no_argument, nullptr, 'D'},
Expand All @@ -158,6 +162,8 @@ int main(int argc, char** argv)
Action action = ACTION_LAUNCH;
bool enableUI = true;
bool flushLog = false;
bool respawnAll = false;
bool respawnObey = true;
bool startNodes = true;
double stopTimeout = rosmon::launch::LaunchConfig::DEFAULT_STOP_TIMEOUT;
uint64_t memoryLimit = rosmon::launch::LaunchConfig::DEFAULT_MEMORY_LIMIT;
Expand Down Expand Up @@ -264,6 +270,18 @@ int main(int argc, char** argv)
fmt::print(stderr, "Prefix : {}", optarg);
diagnosticsPrefix = std::string(optarg);
break;
case 'R':
if (optarg && (strcmp(optarg,"force_true")==0 || strcmp(optarg,"force_false")==0))
{
respawnAll = strcmp(optarg,"force_true")==0;
respawnObey = false;
}
else if (optarg && !((strcmp(optarg,"obey")==0)))
{
fmt::print(stderr, "Bad value for --respawn-attr argument: '{}'\n", optarg);
return 1;
}
break;
}
}

Expand Down Expand Up @@ -352,6 +370,7 @@ int main(int argc, char** argv)
config->setDefaultStopTimeout(stopTimeout);
config->setDefaultCPULimit(cpuLimit);
config->setDefaultMemoryLimit(memoryLimit);
config->setRespawnBehaviour(respawnAll, respawnObey);

// Parse launch file arguments from command line
for(int i = firstArg; i < argc; ++i)
Expand Down
1 change: 1 addition & 0 deletions rosmon_core/test/xml/test_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ TEST_CASE("node args", "[node]")
TEST_CASE("node respawn", "[node]")
{
LaunchConfig config;
config.setRespawnBehaviour(false, true);
config.parseString(R"EOF(
<launch>
<node name="test_node" pkg="rosmon_core" type="abort" respawn="true" respawn_delay="10" />
Expand Down