mirror of
https://github.com/EvernodeXRPL/sashimono.git
synced 2026-08-01 03:21:05 +00:00
Evernode setup installer. (#87)
This commit is contained in:
48
src/main.cpp
48
src/main.cpp
@@ -13,15 +13,15 @@
|
||||
#include "util/util.hpp"
|
||||
#include "killswitch/killswitch.h"
|
||||
|
||||
#define PARSE_ERROR \
|
||||
{ \
|
||||
std::cerr << "Arguments mismatch.\n"; \
|
||||
std::cerr << "Usage:\n"; \
|
||||
std::cerr << "sagent version\n"; \
|
||||
std::cerr << "sagent new [data_dir] [cgrulesengd_service] [host_addr] [registry_addr]\n"; \
|
||||
std::cerr << "sagent run [data_dir]\n"; \
|
||||
std::cerr << "Example: sagent run /etc/sashimono\n"; \
|
||||
return -1; \
|
||||
#define PARSE_ERROR \
|
||||
{ \
|
||||
std::cerr << "Arguments mismatch.\n"; \
|
||||
std::cerr << "Usage:\n"; \
|
||||
std::cerr << "sagent version\n"; \
|
||||
std::cerr << "sagent new [data_dir] [host_addr] [registry_addr] [inst_count] [cpu_us] [ram_kbytes] [swap_kbytes] [disk_kbytes]\n"; \
|
||||
std::cerr << "sagent run [data_dir]\n"; \
|
||||
std::cerr << "Example: sagent run /etc/sashimono\n"; \
|
||||
return -1; \
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,7 +36,7 @@ int parse_cmd(int argc, char **argv)
|
||||
{
|
||||
conf::ctx.command = argv[1];
|
||||
|
||||
if ((conf::ctx.command == "new" && argc >= 2 && argc <= 6) ||
|
||||
if ((conf::ctx.command == "new" && argc >= 2 && argc <= 10) ||
|
||||
(conf::ctx.command == "run" && argc >= 2 && argc <= 3) ||
|
||||
(conf::ctx.command == "version" && argc == 2))
|
||||
return 0;
|
||||
@@ -118,7 +118,7 @@ int main(int argc, char **argv)
|
||||
// Extract the CLI args
|
||||
// This call will populate conf::ctx
|
||||
if (parse_cmd(argc, argv) != 0)
|
||||
return -1;
|
||||
return 1;
|
||||
|
||||
if (conf::ctx.command == "version")
|
||||
{
|
||||
@@ -129,11 +129,19 @@ int main(int argc, char **argv)
|
||||
conf::set_dir_paths(argv[0], (argc >= 3) ? argv[2] : "");
|
||||
|
||||
// This will create a new config.
|
||||
const std::string cgrulesengd_service = (argc >= 4) ? argv[3] : "";
|
||||
const std::string host_addr = (argc >= 5) ? argv[4] : "";
|
||||
const std::string registry_addr = (argc >= 6) ? argv[5] : "";
|
||||
if (conf::create(cgrulesengd_service, host_addr, registry_addr) != 0)
|
||||
return -1;
|
||||
const std::string host_addr = (argc >= 4) ? argv[3] : "";
|
||||
size_t inst_count = 0, cpu_us = 0, ram_kbytes = 0, swap_kbytes = 0, disk_kbytes = 0;
|
||||
|
||||
if (((argc >= 5) && (util::stoull(argv[4], inst_count) != 0 || inst_count == 0)) ||
|
||||
((argc >= 6) && (util::stoull(argv[5], cpu_us) != 0 || cpu_us == 0)) ||
|
||||
((argc >= 7) && (util::stoull(argv[6], ram_kbytes) != 0 || ram_kbytes == 0)) ||
|
||||
((argc >= 8) && (util::stoull(argv[7], swap_kbytes) != 0 || swap_kbytes == 0)) ||
|
||||
((argc >= 9) && (util::stoull(argv[8], disk_kbytes) != 0 || disk_kbytes == 0)) ||
|
||||
conf::create(host_addr, "", inst_count, cpu_us, ram_kbytes, swap_kbytes, disk_kbytes) != 0)
|
||||
{
|
||||
std::cerr << "Invalid Sashimono Agent config creation args.\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (conf::ctx.command == "run")
|
||||
{
|
||||
@@ -142,16 +150,16 @@ int main(int argc, char **argv)
|
||||
if (kill_switch(util::get_epoch_milliseconds()))
|
||||
{
|
||||
std::cerr << "Sashimono Agent usage limit failure.\n";
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (conf::init() != 0)
|
||||
return -1;
|
||||
return 1;
|
||||
|
||||
salog::init(); // Initialize logger for SA.
|
||||
|
||||
if (crypto::init() == -1)
|
||||
return -1;
|
||||
return 1;
|
||||
|
||||
LOG_INFO << "Sashimono agent (version " << version::AGENT_VERSION << ")";
|
||||
LOG_INFO << "Log level: " << conf::cfg.log.log_level;
|
||||
@@ -160,7 +168,7 @@ int main(int argc, char **argv)
|
||||
if (comm::init() == -1 || hp::init() == -1)
|
||||
{
|
||||
deinit();
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// After initializing primary subsystems, register the exit handler.
|
||||
|
||||
Reference in New Issue
Block a user