Added .service
This commit is contained in:
parent
2bb7010dca
commit
a5a320cf94
16
src/config.c
16
src/config.c
|
|
@ -19,12 +19,12 @@
|
||||||
static int extract_val_string(char ** output, toml_table_t *table, char* name) {
|
static int extract_val_string(char ** output, toml_table_t *table, char* name) {
|
||||||
toml_raw_t raw;
|
toml_raw_t raw;
|
||||||
if (0 == (raw = toml_raw_in(table, name))) {
|
if (0 == (raw = toml_raw_in(table, name))) {
|
||||||
syslog_err("[itss] [config] error extracting %s from file", name);
|
syslog_err("[facilities] [config] error extracting %s from file", name);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toml_rtos(raw, (char**) output)) {
|
if (toml_rtos(raw, (char**) output)) {
|
||||||
syslog_err("[itss] [config] error extracting %s to string", name);
|
syslog_err("[facilities] [config] error extracting %s to string", name);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,12 +34,12 @@ static int extract_val_string(char ** output, toml_table_t *table, char* name) {
|
||||||
static int extract_val_bool(int * output, toml_table_t *table, char* name) {
|
static int extract_val_bool(int * output, toml_table_t *table, char* name) {
|
||||||
toml_raw_t raw;
|
toml_raw_t raw;
|
||||||
if (0 == (raw = toml_raw_in(table, name))) {
|
if (0 == (raw = toml_raw_in(table, name))) {
|
||||||
syslog_err("[itss] [config] error extracting %s from file", name);
|
syslog_err("[facilities] [config] error extracting %s from file", name);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toml_rtob(raw, output)) {
|
if (toml_rtob(raw, output)) {
|
||||||
syslog_err("[itss] [config] error extracting %s to bool", name);
|
syslog_err("[facilities] [config] error extracting %s to bool", name);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,12 +49,12 @@ static int extract_val_bool(int * output, toml_table_t *table, char* name) {
|
||||||
static int extract_val_int(int64_t * output, toml_table_t *table, char* name) {
|
static int extract_val_int(int64_t * output, toml_table_t *table, char* name) {
|
||||||
toml_raw_t raw;
|
toml_raw_t raw;
|
||||||
if (0 == (raw = toml_raw_in(table, name))) {
|
if (0 == (raw = toml_raw_in(table, name))) {
|
||||||
syslog_err("[itss] [config] error extracting %s from file", name);
|
syslog_err("[facilities] [config] error extracting %s from file", name);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toml_rtoi(raw, output)) {
|
if (toml_rtoi(raw, output)) {
|
||||||
syslog_err("[itss] [config] error extracting %s to int", name);
|
syslog_err("[facilities] [config] error extracting %s to int", name);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,7 +88,7 @@ int itss_config(void* facilities_s, char* config_file) {
|
||||||
// Tables
|
// Tables
|
||||||
toml_table_t *general, *general_station_id;
|
toml_table_t *general, *general_station_id;
|
||||||
|
|
||||||
if (0 == (general = toml_table_in(conf, "general"))) {syslog_err("[itss] [config] failed locating [general] table"); return 1;}
|
if (0 == (general = toml_table_in(conf, "general"))) {syslog_err("[facilities] [config] failed locating [general] table"); return 1;}
|
||||||
if (0 == (general_station_id = toml_table_in(general, "station-id"))) {syslog_err("CONFIG: Failed locating [general] station-id table"); return 1;}
|
if (0 == (general_station_id = toml_table_in(general, "station-id"))) {syslog_err("CONFIG: Failed locating [general] station-id table"); return 1;}
|
||||||
|
|
||||||
// Values
|
// Values
|
||||||
|
|
@ -100,7 +100,7 @@ int itss_config(void* facilities_s, char* config_file) {
|
||||||
} else if (strcmp("rsu", itss_type) == 0) {
|
} else if (strcmp("rsu", itss_type) == 0) {
|
||||||
facilities->station_type = 15;
|
facilities->station_type = 15;
|
||||||
} else {
|
} else {
|
||||||
syslog_err("[itss] [config] Unrecognized ITSS type, running as unkown");
|
syslog_err("[facilities] [config] Unrecognized ITSS type, running as unkown");
|
||||||
facilities->station_type = 0;
|
facilities->station_type = 0;
|
||||||
}
|
}
|
||||||
free(itss_type);
|
free(itss_type);
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,11 @@
|
||||||
#include <it2s-btp.h>
|
#include <it2s-btp.h>
|
||||||
|
|
||||||
#include <zmq.h>
|
#include <zmq.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#define syslog_info(msg, ...) syslog(LOG_INFO, msg, ##__VA_ARGS__)
|
#define syslog_info(msg, ...) syslog(LOG_INFO, msg, ##__VA_ARGS__)
|
||||||
#define syslog_emerg(msg, ...) syslog(LOG_EMERG, "%s:%d [" msg "]", __func__, __LINE__, ##__VA_ARGS__)
|
#define syslog_emerg(msg, ...) syslog(LOG_EMERG, "%s:%d [" msg "]", __func__, __LINE__, ##__VA_ARGS__)
|
||||||
|
|
@ -258,7 +260,7 @@ static int facilities_request(facilities_t *facilities, void* responder, uint8_t
|
||||||
transmission_duration = valid_to - valid_from;
|
transmission_duration = valid_to - valid_from;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Respond to [itss]
|
// Respond to [applications]
|
||||||
fdres->code = FacilitiesResultCode_accepted;
|
fdres->code = FacilitiesResultCode_accepted;
|
||||||
fdres_oer = malloc(16);
|
fdres_oer = malloc(16);
|
||||||
enc = oer_encode_to_buffer(&asn_DEF_FacilitiesDataResult, NULL, fdres, fdres_oer, 16);
|
enc = oer_encode_to_buffer(&asn_DEF_FacilitiesDataResult, NULL, fdres, fdres_oer, 16);
|
||||||
|
|
@ -433,8 +435,8 @@ void* tx(void* fc) {
|
||||||
|
|
||||||
uint8_t code;
|
uint8_t code;
|
||||||
|
|
||||||
void* application_socket = zmq_socket(facilities->ctx, ZMQ_REQ);
|
void* applications_socket = zmq_socket(facilities->ctx, ZMQ_REQ);
|
||||||
zmq_connect(application_socket, APPLICATION_ADDRESS);
|
zmq_connect(applications_socket, APPLICATION_ADDRESS);
|
||||||
|
|
||||||
void* transport_socket = zmq_socket(facilities->ctx, ZMQ_REQ);
|
void* transport_socket = zmq_socket(facilities->ctx, ZMQ_REQ);
|
||||||
zmq_connect(transport_socket, TRANSPORT_ADDRESS);
|
zmq_connect(transport_socket, TRANSPORT_ADDRESS);
|
||||||
|
|
@ -465,8 +467,8 @@ void* tx(void* fc) {
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
syslog_debug("[facilities]-> sending FDI to ->[application] (%dB)", stream->packet_len[i]);
|
syslog_debug("[facilities]-> sending FDI to ->[application] (%dB)", stream->packet_len[i]);
|
||||||
zmq_send(application_socket, stream->packet[i], stream->packet_len[i], 0);
|
zmq_send(applications_socket, stream->packet[i], stream->packet_len[i], 0);
|
||||||
zmq_recv(application_socket, &code, 1, 0);
|
zmq_recv(applications_socket, &code, 1, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -481,6 +483,11 @@ int main() {
|
||||||
facilities_t facilities;
|
facilities_t facilities;
|
||||||
facilities.exit = false;
|
facilities.exit = false;
|
||||||
|
|
||||||
|
struct stat st = {0};
|
||||||
|
if (stat("/tmp/itss", &st) == -1) {
|
||||||
|
mkdir("/tmp/itss", 0777);
|
||||||
|
}
|
||||||
|
|
||||||
time_t t;
|
time_t t;
|
||||||
srand((unsigned) time(&t));
|
srand((unsigned) time(&t));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
[Unit]
|
||||||
|
Description=it2s-itss-facilities service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
UMask=0000
|
||||||
|
Type=simple
|
||||||
|
ExecStart=/usr/bin/it2s-itss-facilities
|
||||||
|
KillMode=mixed
|
||||||
|
SuccessExitStatus=0 SIGKILL SIGHUP KILL
|
||||||
|
KillSignal=SIGINT
|
||||||
|
TimeoutStopSec=5
|
||||||
|
ExecStopPost=/usr/bin/systemctl daemon-reload
|
||||||
|
ExecStopPost=/usr/bin/systemctl reset-failed
|
||||||
|
SendSIGHUP=yes
|
||||||
|
SendSIGKILL=yes
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
|
||||||
Loading…
Reference in New Issue