Added files for Linux and OS X
This commit is contained in:
parent
23ec3ede95
commit
8d0a9871d8
5 changed files with 81 additions and 25 deletions
|
@ -2,6 +2,7 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <getopt.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
@ -11,6 +12,7 @@
|
|||
#include <arpa/inet.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <syslog.h>
|
||||
#include <signal.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
|
@ -88,6 +90,10 @@
|
|||
#endif
|
||||
|
||||
|
||||
#define MODE_CONSOLE (1 << 0)
|
||||
#define MODE_SYSLOG (1 << 1)
|
||||
#define MODE_DAEMON (1 << 2)
|
||||
|
||||
#define MEDIA_PORT_COUNT (REWIND_TYPE_ANALOG_DATA - REWIND_TYPE_SLOT_1_VOICE + 1)
|
||||
#define EVENT_LIST_LENGTH (4 + 1 + 3 + MEDIA_PORT_COUNT)
|
||||
|
||||
|
@ -95,12 +101,25 @@
|
|||
#define EXPIRATION_TIME 20
|
||||
|
||||
|
||||
int serviceMode = MODE_CONSOLE;
|
||||
|
||||
void print(const char* format, ...)
|
||||
{
|
||||
va_list arguments;
|
||||
va_start(arguments, format);
|
||||
if (serviceMode & MODE_CONSOLE)
|
||||
vprintf(format, arguments);
|
||||
if (serviceMode & MODE_SYSLOG)
|
||||
vsyslog(LOG_INFO, format, arguments);
|
||||
va_end(arguments);
|
||||
}
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
printf("\n");
|
||||
printf("CronosAgent for BrandMeister DMR Master Server\n");
|
||||
printf("Copyright 2016 Artem Prilutskiy (R3ABM, cyanide.burnout@gmail.com)\n");
|
||||
printf("\n");
|
||||
print("\n");
|
||||
print("CronosAgent for BrandMeister DMR Master Server\n");
|
||||
print("Copyright 2016 Artem Prilutskiy (R3ABM, cyanide.burnout@gmail.com)\n");
|
||||
print("\n");
|
||||
|
||||
// Parameters of server
|
||||
|
||||
|
@ -133,11 +152,12 @@ int main(int argc, const char* argv[])
|
|||
{ "server-port", required_argument, NULL, 'p' },
|
||||
{ "base-port", required_argument, NULL, 'b' },
|
||||
{ "trap-port", required_argument, NULL, 't' },
|
||||
{ "service-mode", required_argument, NULL, 'm' },
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
int selection = 0;
|
||||
while ((selection = getopt_long(argc, CAST(char* const*, argv), "n:r:c:w:s:p:b:t:", options, NULL)) != EOF)
|
||||
while ((selection = getopt_long(argc, CAST(char* const*, argv), "n:r:c:w:s:p:b:t:m:", options, NULL)) != EOF)
|
||||
switch (selection)
|
||||
{
|
||||
case 'n':
|
||||
|
@ -171,6 +191,10 @@ int main(int argc, const char* argv[])
|
|||
case 't':
|
||||
proxyTrapPort = strtol(optarg, NULL, 10);
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
serviceMode = strtol(optarg, NULL, 10);
|
||||
break;
|
||||
}
|
||||
|
||||
if ((repeaterNumber == 0) ||
|
||||
|
@ -178,7 +202,7 @@ int main(int argc, const char* argv[])
|
|||
(serverLocation == NULL) ||
|
||||
(repeaterSocketAddress.sin_addr.s_addr == htonl(INADDR_ANY)))
|
||||
{
|
||||
printf(
|
||||
print(
|
||||
"Usage:\n"
|
||||
" %s\n"
|
||||
" --repeater-address <IP address of repeater>\n"
|
||||
|
@ -189,11 +213,26 @@ int main(int argc, const char* argv[])
|
|||
" --server-port <port number of RadioActivity Console>\n"
|
||||
" --base-port <base port for RTP Media>\n"
|
||||
" --trap-port <port for SNMP Traps>\n"
|
||||
" --service-mode <set of bits>\n"
|
||||
" bit 0 - print to standard output\n"
|
||||
" bit 1 - print to system log\n"
|
||||
#ifdef __linux__
|
||||
" bit 2 - run as daemon\n"
|
||||
#endif
|
||||
"\n",
|
||||
argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
if ((serviceMode & MODE_DAEMON) &&
|
||||
(daemon(-1, -1) < 0))
|
||||
{
|
||||
print("Error launching daemon");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Resolve server address
|
||||
|
||||
struct addrinfo hints;
|
||||
|
@ -212,7 +251,7 @@ int main(int argc, const char* argv[])
|
|||
|
||||
if (getaddrinfo(serverLocation, serverPort, &hints, &serverAddress) != 0)
|
||||
{
|
||||
printf("Error resolving server address %s\n", serverLocation);
|
||||
print("Error resolving server address %s\n", serverLocation);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -231,7 +270,7 @@ int main(int argc, const char* argv[])
|
|||
if((remoteHandle < 0) ||
|
||||
(bind(remoteHandle, (struct sockaddr*)&proxySocketAddress, sizeof(proxySocketAddress)) < 0))
|
||||
{
|
||||
printf("Error opening port for Remote Control\n");
|
||||
print("Error opening port for Remote Control\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -240,7 +279,7 @@ int main(int argc, const char* argv[])
|
|||
if((trapHandle < 0) ||
|
||||
(bind(trapHandle, (struct sockaddr*)&proxySocketAddress, sizeof(proxySocketAddress)) < 0))
|
||||
{
|
||||
printf("Error opening port for SNMP Traps\n");
|
||||
print("Error opening port for SNMP Traps\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -251,7 +290,7 @@ int main(int argc, const char* argv[])
|
|||
if((handle < 0) ||
|
||||
(bind(handle, (struct sockaddr*)&proxySocketAddress, sizeof(proxySocketAddress)) < 0))
|
||||
{
|
||||
printf("Error opening port for RTP Media\n");
|
||||
print("Error opening port for RTP Media\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
mediaHandles[index] = handle;
|
||||
|
@ -271,7 +310,7 @@ int main(int argc, const char* argv[])
|
|||
if((uplinkHandle < 0) ||
|
||||
(bind(uplinkHandle, (struct sockaddr*)&uplinkSocketAddress, sizeof(uplinkSocketAddress)) < 0))
|
||||
{
|
||||
printf("Error opening port for Rewind Uplink\n");
|
||||
print("Error opening port for Rewind Uplink\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -417,7 +456,7 @@ int main(int argc, const char* argv[])
|
|||
|
||||
bool running = true;
|
||||
|
||||
printf("Server started\n");
|
||||
print("Server started\n");
|
||||
|
||||
while (running)
|
||||
{
|
||||
|
@ -433,7 +472,7 @@ int main(int argc, const char* argv[])
|
|||
if (count < 0)
|
||||
{
|
||||
int error = errno;
|
||||
printf("Error processing handles: %s (%d)\n", strerror(error), error);
|
||||
print("Error processing handles: %s (%d)\n", strerror(error), error);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -483,13 +522,13 @@ int main(int argc, const char* argv[])
|
|||
if (type == REWIND_TYPE_REPORT)
|
||||
{
|
||||
incomingBuffer->data[length] = '\0';
|
||||
printf("Server message: %s\n", incomingBuffer->data);
|
||||
print("Server message: %s\n", incomingBuffer->data);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (type == REWIND_TYPE_CHALLENGE)
|
||||
{
|
||||
printf("Authenticating with agent\n");
|
||||
print("Authenticating with agent\n");
|
||||
|
||||
memcpy(incomingBuffer->data + length, serverPassword, passwordLength);
|
||||
SHA256(incomingBuffer->data, length + passwordLength, outgoingBuffer->data);
|
||||
|
@ -516,7 +555,7 @@ int main(int argc, const char* argv[])
|
|||
|
||||
if (type == REWIND_TYPE_CLOSE)
|
||||
{
|
||||
printf("Disconnect request received\n");
|
||||
print("Disconnect request received\n");
|
||||
running = false;
|
||||
break;
|
||||
}
|
||||
|
@ -613,7 +652,7 @@ int main(int argc, const char* argv[])
|
|||
#endif
|
||||
if (now.tv_sec > watchDog)
|
||||
{
|
||||
printf("Connection time-out expired\n");
|
||||
print("Connection time-out expired\n");
|
||||
running = false;
|
||||
break;
|
||||
}
|
||||
|
@ -666,7 +705,7 @@ int main(int argc, const char* argv[])
|
|||
}
|
||||
}
|
||||
|
||||
printf("Server stopped\n");
|
||||
print("Server stopped\n");
|
||||
|
||||
// Clean up
|
||||
|
||||
|
|
10
Makefile
10
Makefile
|
@ -1,6 +1,7 @@
|
|||
BUILD := $(shell date -u +%Y%m%d-%H%M%S)
|
||||
OS := $(shell uname -s)
|
||||
|
||||
PREFIX = $(DESTDIR)/opt/CronosAgent
|
||||
TOOLKIT = ../..
|
||||
|
||||
DIRECTORIES = \
|
||||
|
@ -41,6 +42,15 @@ all: build
|
|||
build: $(PREREQUISITES) $(OBJECTS)
|
||||
$(CC) $(OBJECTS) $(FLAGS) $(LIBS) -o cronosagent
|
||||
|
||||
install:
|
||||
install -D -d $(PREFIX)
|
||||
install -o root -g root cronosagent $(PREFIX)
|
||||
install -o root -g root cronosagent.sh $(PREFIX)
|
||||
install -o root -g root cronosagent-init $(PREFIX)
|
||||
install -m 644 -o root -g root Main/brandmeister-monit $(PREFIX)
|
||||
install -m 644 -o root -g root Main/brandmeister.plist $(PREFIX)
|
||||
install -m 644 -o root -g root Main/brandmeister.service $(PREFIX)
|
||||
|
||||
clean:
|
||||
rm -f $(PREREQUISITES) $(OBJECTS) cronosagent
|
||||
rm -f *.d $(TOOLKIT)/*/*.d
|
||||
|
|
|
@ -5,13 +5,13 @@ Afer=network.target
|
|||
[Service]
|
||||
; system.service
|
||||
Type=simple
|
||||
ExecStart=/opt/CronosAgent/cronosagent.sh
|
||||
ExecStart=/opt/CronosAgent/cronosagent.sh 2
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
; system.exec
|
||||
User=cronos
|
||||
Group=cronos
|
||||
StandardOutput=syslog
|
||||
StandardOutput=null
|
||||
WorkingDirectory=/opt/CronosAgent
|
||||
|
||||
[Install]
|
||||
|
|
|
@ -4,10 +4,20 @@ REPEATER_NUMBER=250304
|
|||
REPEATER_ADDRESS=172.33.20.136
|
||||
SERVER_ADDRESS=aesyle.dstar.su
|
||||
SERVER_PASSWORD=passw0rd
|
||||
SERVICE_MODE=1
|
||||
|
||||
if [ -n "$!" ]
|
||||
then
|
||||
# 1 - print to standard output
|
||||
# 2 - print to system log
|
||||
# 6 - run as daemon and print to system log
|
||||
SERVICE_MODE=$1
|
||||
fi
|
||||
|
||||
./cronosagent \
|
||||
--trap-port 8162 \
|
||||
--repeater-number ${REPEATER_NUMBER} \
|
||||
--repeater-address ${REPEATER_ADDRESS} \
|
||||
--server-password ${SERVER_PASSWORD} \
|
||||
--server-address ${SERVER_ADDRESS}
|
||||
--server-address ${SERVER_ADDRESS} \
|
||||
--service-mode ${SERVICE_MODE}
|
||||
|
|
5
debian/postinst
vendored
5
debian/postinst
vendored
|
@ -15,14 +15,11 @@ then
|
|||
ln -s -f $PREFIX/cronosagent.service /etc/systemd/system/multi-user.target.wants/cronosagent.service
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl start systemd-modules-load
|
||||
|
||||
systemctl restart cronosagent
|
||||
else
|
||||
ln -s -f $PREFIX/cronosagent-daemon /etc/init.d/cronosagent
|
||||
ln -s -f $PREFIX/cronosagent-init /etc/init.d/cronosagent
|
||||
|
||||
update-rc.d cronosagent defaults
|
||||
|
||||
service cronosagent restart
|
||||
|
||||
if [ -d /etc/monit/conf.d ]
|
||||
|
|
Loading…
Add table
Reference in a new issue