2020-09-17 23:02:40 +03:00
|
|
|
// Copyright (c) Vitaliy Filippov, 2019+
|
2021-02-06 01:26:07 +03:00
|
|
|
// License: VNPL-1.1 (see README.md for details)
|
2020-09-17 23:02:40 +03:00
|
|
|
|
2019-12-15 01:11:51 +03:00
|
|
|
#include "osd.h"
|
|
|
|
|
2020-01-15 23:20:07 +03:00
|
|
|
#include <signal.h>
|
|
|
|
|
2020-04-24 16:46:02 +03:00
|
|
|
static osd_t *osd = NULL;
|
2020-04-26 01:33:50 +03:00
|
|
|
static bool force_stopping = false;
|
2020-04-24 16:46:02 +03:00
|
|
|
|
|
|
|
static void handle_sigint(int sig)
|
2020-01-15 23:20:07 +03:00
|
|
|
{
|
2020-04-26 01:33:50 +03:00
|
|
|
if (osd && !force_stopping)
|
2020-04-24 16:46:02 +03:00
|
|
|
{
|
2020-04-26 01:33:50 +03:00
|
|
|
force_stopping = true;
|
2020-04-27 14:32:59 +03:00
|
|
|
osd->force_stop(0);
|
2020-04-24 16:46:02 +03:00
|
|
|
return;
|
|
|
|
}
|
2020-01-15 23:20:07 +03:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2023-11-04 13:32:12 +03:00
|
|
|
static const char* help_text =
|
|
|
|
"Vitastor OSD (block object storage daemon) " VERSION "\n"
|
|
|
|
"(c) Vitaliy Filippov, 2019+ (VNPL-1.1)\n"
|
|
|
|
"\n"
|
|
|
|
"OSDs are usually started by vitastor-disk.\n"
|
|
|
|
"Manual usage: vitastor-osd [--option value] ...\n"
|
|
|
|
;
|
|
|
|
|
2019-12-15 01:11:51 +03:00
|
|
|
int main(int narg, char *args[])
|
|
|
|
{
|
2020-09-11 16:52:51 +03:00
|
|
|
setvbuf(stdout, NULL, _IONBF, 0);
|
|
|
|
setvbuf(stderr, NULL, _IONBF, 0);
|
2020-02-23 18:57:20 +03:00
|
|
|
if (sizeof(osd_any_op_t) > OSD_PACKET_SIZE ||
|
|
|
|
sizeof(osd_any_reply_t) > OSD_PACKET_SIZE)
|
2019-12-15 01:11:51 +03:00
|
|
|
{
|
|
|
|
perror("BUG: too small packet size");
|
|
|
|
return 1;
|
|
|
|
}
|
2021-04-30 00:46:03 +03:00
|
|
|
json11::Json::object config;
|
2020-01-15 23:20:07 +03:00
|
|
|
for (int i = 1; i < narg; i++)
|
|
|
|
{
|
|
|
|
if (args[i][0] == '-' && args[i][1] == '-' && i < narg-1)
|
|
|
|
{
|
|
|
|
char *opt = args[i]+2;
|
2021-04-30 00:46:03 +03:00
|
|
|
config[std::string(opt)] = std::string(args[++i]);
|
2020-01-15 23:20:07 +03:00
|
|
|
}
|
2023-11-04 13:32:12 +03:00
|
|
|
else if (!strcmp(args[i], "--help"))
|
|
|
|
{
|
|
|
|
printf("%s", help_text);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!config.size())
|
|
|
|
{
|
|
|
|
printf("%s", help_text);
|
|
|
|
return 1;
|
2020-01-15 23:20:07 +03:00
|
|
|
}
|
|
|
|
signal(SIGINT, handle_sigint);
|
2020-04-24 16:46:02 +03:00
|
|
|
signal(SIGTERM, handle_sigint);
|
2023-11-20 03:03:33 +03:00
|
|
|
ring_loop_t *ringloop = new ring_loop_t(RINGLOOP_DEFAULT_SIZE);
|
2021-01-10 11:57:41 +03:00
|
|
|
osd = new osd_t(config, ringloop);
|
2019-12-15 01:11:51 +03:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
ringloop->loop();
|
|
|
|
ringloop->wait();
|
|
|
|
}
|
|
|
|
delete osd;
|
|
|
|
delete ringloop;
|
|
|
|
return 0;
|
|
|
|
}
|