2015-09-13 20:25:26 +00:00
|
|
|
///
|
2020-06-15 00:31:42 +00:00
|
|
|
/// Copyright 2015-2020 Oliver Giles
|
2015-09-13 20:25:26 +00:00
|
|
|
///
|
|
|
|
/// This file is part of Laminar
|
|
|
|
///
|
|
|
|
/// Laminar is free software: you can redistribute it and/or modify
|
|
|
|
/// it under the terms of the GNU General Public License as published by
|
|
|
|
/// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
/// (at your option) any later version.
|
|
|
|
///
|
|
|
|
/// Laminar is distributed in the hope that it will be useful,
|
|
|
|
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
/// GNU General Public License for more details.
|
|
|
|
///
|
|
|
|
/// You should have received a copy of the GNU General Public License
|
|
|
|
/// along with Laminar. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
///
|
|
|
|
#include "laminar.h"
|
2019-12-21 13:29:37 +00:00
|
|
|
#include "leader.h"
|
2019-10-05 17:06:35 +00:00
|
|
|
#include "server.h"
|
2015-12-06 11:36:12 +00:00
|
|
|
#include "log.h"
|
2020-06-15 00:31:42 +00:00
|
|
|
#include <fcntl.h>
|
2018-08-03 11:36:24 +00:00
|
|
|
#include <kj/async-unix.h>
|
2018-09-28 07:36:10 +00:00
|
|
|
#include <kj/filesystem.h>
|
2020-06-15 00:31:42 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2015-09-13 20:25:26 +00:00
|
|
|
|
2016-07-25 11:59:45 +00:00
|
|
|
static Laminar* laminar;
|
2019-10-05 17:06:35 +00:00
|
|
|
static Server* server;
|
2016-07-25 11:59:45 +00:00
|
|
|
|
|
|
|
static void laminar_quit(int) {
|
2019-10-05 17:06:35 +00:00
|
|
|
// Abort current jobs. Most of the time this isn't necessary since
|
|
|
|
// systemd stop or other kill mechanism will send SIGTERM to the whole
|
|
|
|
// process group.
|
|
|
|
laminar->abortAll();
|
|
|
|
server->stop();
|
2016-07-25 11:59:45 +00:00
|
|
|
}
|
2015-09-13 20:25:26 +00:00
|
|
|
|
2019-10-05 17:06:35 +00:00
|
|
|
namespace {
|
|
|
|
constexpr const char* INTADDR_RPC_DEFAULT = "unix-abstract:laminar";
|
|
|
|
constexpr const char* INTADDR_HTTP_DEFAULT = "*:8080";
|
|
|
|
constexpr const char* ARCHIVE_URL_DEFAULT = "/archive/";
|
|
|
|
}
|
|
|
|
|
2015-09-13 20:25:26 +00:00
|
|
|
int main(int argc, char** argv) {
|
2019-12-21 13:29:37 +00:00
|
|
|
if(argv[0][0] == '{')
|
|
|
|
return leader_main();
|
|
|
|
|
2015-09-13 20:25:26 +00:00
|
|
|
for(int i = 1; i < argc; ++i) {
|
|
|
|
if(strcmp(argv[i], "-v") == 0) {
|
|
|
|
kj::_::Debug::setLogLevel(kj::_::Debug::Severity::INFO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-15 00:31:42 +00:00
|
|
|
// The parent process hopefully connected stdin to /dev/null, but
|
|
|
|
// do it again here just in case. This is important because stdin
|
|
|
|
// is inherited to job runs via the leader process, and some
|
|
|
|
// processes misbehave if they can successfully block on reading
|
|
|
|
// from stdin.
|
|
|
|
close(STDIN_FILENO);
|
|
|
|
LASSERT(open("/dev/null", O_RDONLY) == STDIN_FILENO);
|
|
|
|
|
2019-10-05 17:06:35 +00:00
|
|
|
auto ioContext = kj::setupAsyncIo();
|
|
|
|
|
|
|
|
Settings settings;
|
|
|
|
// Default values when none were supplied in $LAMINAR_CONF_FILE (/etc/laminar.conf)
|
|
|
|
settings.home = getenv("LAMINAR_HOME") ?: "/var/lib/laminar";
|
|
|
|
settings.bind_rpc = getenv("LAMINAR_BIND_RPC") ?: INTADDR_RPC_DEFAULT;
|
|
|
|
settings.bind_http = getenv("LAMINAR_BIND_HTTP") ?: INTADDR_HTTP_DEFAULT;
|
|
|
|
settings.archive_url = getenv("LAMINAR_ARCHIVE_URL") ?: ARCHIVE_URL_DEFAULT;
|
|
|
|
|
|
|
|
server = new Server(ioContext);
|
|
|
|
laminar = new Laminar(*server, settings);
|
|
|
|
|
2018-08-03 11:36:24 +00:00
|
|
|
kj::UnixEventPort::captureChildExit();
|
2018-09-28 07:36:10 +00:00
|
|
|
|
2016-07-25 11:59:45 +00:00
|
|
|
signal(SIGINT, &laminar_quit);
|
|
|
|
signal(SIGTERM, &laminar_quit);
|
2018-08-03 11:36:24 +00:00
|
|
|
|
2019-10-05 17:06:35 +00:00
|
|
|
server->start();
|
2015-09-13 20:25:26 +00:00
|
|
|
|
2016-07-25 11:59:45 +00:00
|
|
|
delete laminar;
|
2019-10-05 17:06:35 +00:00
|
|
|
delete server;
|
2016-07-25 11:59:45 +00:00
|
|
|
|
|
|
|
LLOG(INFO, "Clean exit");
|
2015-09-13 20:25:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|