source: ogServer-Git/src/main.c @ a67f27a

Last change on this file since a67f27a was f068a79, checked in by OpenGnSys Support Team <soporte-og@…>, 4 years ago

#988 Add global config variable

This commit makes configuration variable global.

To use this variable you have to #import "cfg.h".

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/*
2 * Copyright (C) 2020 Soleta Networks <info@soleta.eu>
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Affero General Public License as published by the
6 * Free Software Foundation, version 3.
7 */
8
9#include "ogAdmServer.h"
10#include "dbi.h"
11#include "utils.h"
12#include "list.h"
13#include "rest.h"
14#include "client.h"
15#include "json.h"
16#include "schedule.h"
17#include "core.h"
18#include "cfg.h"
19#include <syslog.h>
20
21#define OG_SERVER_CFG_JSON      "/opt/opengnsys/cfg/ogserver.json"
22
23struct og_server_cfg cfg;
24
25int main(int argc, char *argv[])
26{
27        struct ev_io ev_io_server_rest, ev_io_agent_rest;
28
29        og_loop = ev_default_loop(0);
30
31        if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
32                exit(EXIT_FAILURE);
33
34        openlog("ogserver", LOG_PID, LOG_DAEMON);
35
36        if (!validacionParametros(argc, argv, 1)) // Valida parámetros de ejecución
37                exit(EXIT_FAILURE);
38
39        if (parse_json_config(OG_SERVER_CFG_JSON, &cfg) < 0) {
40                syslog(LOG_INFO, "Falling back to legacy configuration file at %s\n",
41                       szPathFileCfg);
42                if (!tomaConfiguracion(szPathFileCfg))
43                        exit(EXIT_FAILURE);
44        } else {
45                from_json_to_legacy(&cfg);
46        }
47
48        socket_rest = og_socket_server_init("8888");
49        if (socket_rest < 0) {
50                syslog(LOG_ERR, "Cannot open REST API server socket\n");
51                exit(EXIT_FAILURE);
52        }
53
54        ev_io_init(&ev_io_server_rest, og_server_accept_cb, socket_rest, EV_READ);
55        ev_io_start(og_loop, &ev_io_server_rest);
56
57        socket_agent_rest = og_socket_server_init("8889");
58        if (socket_agent_rest < 0) {
59                syslog(LOG_ERR, "Cannot open ogClient server socket\n");
60                exit(EXIT_FAILURE);
61        }
62
63        ev_io_init(&ev_io_agent_rest, og_server_accept_cb, socket_agent_rest, EV_READ);
64        ev_io_start(og_loop, &ev_io_agent_rest);
65
66        if (og_dbi_schedule_get() < 0) {
67                syslog(LOG_ERR, "Cannot connect to database\n");
68                exit(EXIT_FAILURE);
69        }
70
71        og_schedule_next(og_loop);
72
73        syslog(LOG_INFO, "Waiting for connections\n");
74
75        while (1)
76                ev_loop(og_loop, 0);
77
78        exit(EXIT_SUCCESS);
79}
Note: See TracBrowser for help on using the repository browser.