source: ogServer-Git/sources/main.c @ c0f5d2c

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

#971 syslog on error from the initialization path

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[48de515]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 <syslog.h>
19
20int main(int argc, char *argv[])
21{
22        struct ev_io ev_io_server_rest, ev_io_agent_rest;
23        int i;
24
25        og_loop = ev_default_loop(0);
26
27        if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
28                exit(EXIT_FAILURE);
29
[1a406b2]30        openlog("ogserver", LOG_PID, LOG_DAEMON);
[48de515]31
32        if (!validacionParametros(argc, argv, 1)) // Valida parámetros de ejecución
33                exit(EXIT_FAILURE);
34
35        if (!tomaConfiguracion(szPathFileCfg)) { // Toma parametros de configuracion
36                exit(EXIT_FAILURE);
37        }
38
39        for (i = 0; i < MAXIMOS_CLIENTES; i++) {
40                tbsockets[i].ip[0] = '\0';
41                tbsockets[i].cli = NULL;
42        }
43
44        socket_rest = og_socket_server_init("8888");
[f6f1f18]45        if (socket_rest < 0) {
46                syslog(LOG_ERR, "Cannot open REST API server socket\n");
[48de515]47                exit(EXIT_FAILURE);
[f6f1f18]48        }
[48de515]49
50        ev_io_init(&ev_io_server_rest, og_server_accept_cb, socket_rest, EV_READ);
51        ev_io_start(og_loop, &ev_io_server_rest);
52
53        socket_agent_rest = og_socket_server_init("8889");
[f6f1f18]54        if (socket_agent_rest < 0) {
55                syslog(LOG_ERR, "Cannot open ogClient server socket\n");
[48de515]56                exit(EXIT_FAILURE);
[f6f1f18]57        }
[48de515]58
59        ev_io_init(&ev_io_agent_rest, og_server_accept_cb, socket_agent_rest, EV_READ);
60        ev_io_start(og_loop, &ev_io_agent_rest);
61
[f6f1f18]62        if (og_dbi_schedule_get() < 0) {
63                syslog(LOG_ERR, "Cannot connect to database\n");
[48de515]64                exit(EXIT_FAILURE);
[f6f1f18]65        }
[48de515]66
67        og_schedule_next(og_loop);
68
69        syslog(LOG_INFO, "Waiting for connections\n");
70
71        while (1)
72                ev_loop(og_loop, 0);
73
74        exit(EXIT_SUCCESS);
75}
Note: See TracBrowser for help on using the repository browser.