aboutsummaryrefslogtreecommitdiffstats
path: root/logforwarder/src/apps/vespa-logforwarder-start/main.cpp
blob: 8fc74fcac8ee3df7c359174f287c89c6b944cb05 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <csignal>
#include <unistd.h>

#include <vespa/log/log.h>
LOG_SETUP("vespa-logforwarder-start");

#include "cf-handler.h"
#include <vespa/vespalib/util/sig_catch.h>

class Wrapper {
    const char *_configId;
public:
    Wrapper(const char *cfid) : _configId(cfid) {}
    void run() {
        vespalib::SigCatch catcher;
        CfHandler handler;
        handler.start(_configId);
        while (! catcher.receivedStopSignal()) {
            handler.check();
            usleep(12500); // Avoid busy looping;
        }
    }
};

int
main(int argc, char** argv)
{
    int c = getopt(argc, argv, "c:");
    if (c != 'c') {
        LOG(error, "Usage: %s -c <config-id>", argv[0]);
        exit(EXIT_FAILURE);
    }
    Wrapper wrapper(optarg);
    wrapper.run();
    return 0;
}