-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
56 lines (47 loc) · 1.45 KB
/
main.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
#include "performer.hpp"
#include "config.hpp"
#include "logger.hpp"
#include <iostream>
#include <memory>
#define BH_MASTER
void fallback_error (const char*);
int main(int argc, char *argv[]) {
std::shared_ptr<Config> cnf;
std::shared_ptr<Logger> lgr;
try {
cnf = std::make_shared<Config>(argc, argv);
} catch (std::runtime_error& e) {
fallback_error(e.what());
return 1;
}
try {
lgr = std::make_shared<Logger>(cnf);
} catch (std::runtime_error& e) {
fallback_error(e.what());
return 1;
}
try {
/* NOTE:
* Read configuration file to use it everywhere in the program later
*/
Performer maintenance(cnf, lgr);
maintenance.shutdownSynergy();
maintenance.transferBackups();
maintenance.cleanBackups();
maintenance.startSynergy();
maintenance.sendMail();
}
catch (std::runtime_error& e) {
*lgr << lgr->date() << "[ERROR]: Runtime error: \"" << e.what() << "\"";
std::cout << "[FATAL]: Runtime error: \"" << e.what() << "\"\n";
return 1;
}
return 0;
}
void fallback_error (const char* error_message) {
ofstream error;
error.open("/tmp/hdsh.error.log", ofstream::out | ofstream::app);
error << "[FATAL]: Runtime error: \"" << error_message << "\"";
error.close();
std::cout << "[FATAL]: Initialization failed. See \"/tmp/hdsh.error.log\" for details" << std::endl;
}