-
Notifications
You must be signed in to change notification settings - Fork 0
/
MediaCentre.cpp
137 lines (113 loc) · 3.31 KB
/
MediaCentre.cpp
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
Copyright 2017 Seth Traverse
This file is part of ViaWare Media Centre.
ViaWare Media Centre is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ViaWare Media Centre is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
with ViaWare Media Centre. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <cstdio>
#include <cstdlib>
#include <syslog.h>
#include "vmc-libutils/Config.h"
#include "vmc-libctrl/Application.h"
#include "vmc-libselect/InputManager.h"
#include "vmc-libstream/OmxPlaylistManager.h"
#define VERSION "0.0.1"
json defaultConfig = {
{"http", {
{"host", "0.0.0.0"},
{"port", 8080}}
},
{"database", {
{"host", "localhost"},
{"port", 3306},
{"user", "username"},
{"pass", "password"},
{"database", "vmc"}}
},
{"frontend", {
{"folder", "../"}}
},
{"app", {
{"registration", true},
{"guest", true}
}}
};
int main(int argc, char **argv)
{
std::cout << "Running ViaWare Control Server v" << VERSION << std::endl;
int flag;
bool daemon = false;
char const *log = "/var/log/vmc.log";
char const *config = "/etc/vmc/config.json";
uid_t daemonUser = 0;
gid_t daemonGroup = 0;
while ((flag = getopt(argc, argv, "dl:c:u:g:")) != -1)
{
switch(flag)
{
case 'd':
daemon = true;
break;
case 'l':
log = optarg;
break;
case 'c':
config = optarg;
break;
case 'u':
daemonUser = atol(optarg);
break;
case 'g':
daemonGroup = atol(optarg);
break;
}
}
openlog("vmc-application", LOG_PID, LOG_USER);
if (daemon)
{
openlog("vmc-parent", LOG_PID, LOG_DAEMON);
syslog(LOG_NOTICE, "Starting vmc daemon...");
pid_t pid = fork();
if (pid < 0)
{
syslog(LOG_NOTICE, "Could not fork");
}
if (pid > 0) exit(EXIT_SUCCESS);
openlog("vmc", LOG_PID, LOG_DAEMON);
umask(0);
freopen(log, "a", stdout);
pid_t sid = setsid();
if (sid < 0)
{
syslog(LOG_NOTICE, "Could not setsid");
exit(EXIT_FAILURE);
}
if (chdir("/") < 0)
{
syslog(LOG_NOTICE, "Could not chdir");
exit(EXIT_FAILURE);
}
close(STDIN_FILENO);
close(STDERR_FILENO);
setgid(daemonGroup);
setuid(daemonUser);
}
syslog(LOG_NOTICE, "Starting the vmc application...");
vmc::Config conf(config, defaultConfig);
vmc::stream::OmxPlaylistManager playlistManager;
vmc::input::InputManager inputManager;
vmc::ctrl::start(&conf, &inputManager, &playlistManager);
return 0;
}