More work on running as daemon.

pull/22/head
weetmuts 2019-02-23 23:11:09 +01:00
rodzic 54ffc41a9f
commit b68cadfdc8
10 zmienionych plików z 38 dodań i 10 usunięć

Wyświetl plik

@ -96,7 +96,7 @@ Type=simple
#Restart=always
RestartSec=1
User=wmbusmeters
ExecStart=/usr/sbin/wmbusmetersd
ExecStart=/usr/bin/wmbusmeters --useconfig
[Install]
WantedBy=multi-user.target

Wyświetl plik

@ -165,7 +165,6 @@ void startUsingCommandline(CommandLine *cmdline)
auto output = unique_ptr<Printer>(new Printer(cmdline->json, cmdline->fields,
cmdline->separator, cmdline->meterfiles, cmdline->meterfiles_dir,
cmdline->shells));
vector<unique_ptr<Meter>> meters;
if (cmdline->meters.size() > 0) {
@ -232,6 +231,7 @@ void startUsingCommandline(CommandLine *cmdline)
wmbus->simulate();
}
notice("wmbusmeters waiting for telegrams\n");
manager->waitForStop();
}
@ -265,10 +265,10 @@ void startDaemon()
setlogmask(LOG_UPTO (LOG_NOTICE));
openlog("wmbusmetersd", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
syslog(LOG_NOTICE, "wmbusmeters started by User %d", getuid ());
enableSyslog();
notice("wmbusmeters started by user %d\n", getuid ());
// Create a new SID for the daemon
pid_t sid = setsid();
if (sid < 0) {

Wyświetl plik

@ -64,6 +64,9 @@ void Printer::printFiles(Meter *meter, string &human_readable, string &fields, s
memset(filename, 0, sizeof(filename));
snprintf(filename, 127, "%s/%s", meterfiles_dir_.c_str(), meter->name().c_str());
output = fopen(filename, "w");
if (!output) {
warning("Could not open file \"%s\" for writing!\n", filename);
}
}
if (json_) {

Wyświetl plik

@ -192,6 +192,28 @@ bool isLogTelegramsEnabled() {
return log_telegrams_enabled_;
}
void info(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
if (syslog_enabled_) {
vsyslog(LOG_INFO, fmt, args);
} else {
vprintf(fmt, args);
}
va_end(args);
}
void notice(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
if (syslog_enabled_) {
vsyslog(LOG_NOTICE, fmt, args);
} else {
vprintf(fmt, args);
}
va_end(args);
}
void warning(const char* fmt, ...) {
if (warning_enabled_) {
va_list args;

Wyświetl plik

@ -44,6 +44,8 @@ void error(const char* fmt, ...);
void verbose(const char* fmt, ...);
void debug(const char* fmt, ...);
void warning(const char* fmt, ...);
void info(const char* fmt, ...);
void notice(const char* fmt, ...);
void warningSilenced(bool b);
void verboseEnabled(bool b);

Wyświetl plik

@ -13,9 +13,10 @@ $PROG --robot=json simulations/simulation_c1.txt \
Vadden multical21 44556677 "" \
MyElectricity omnipower 15947107 "" \
> $TEST/test_output.txt
if [ "$?" == "0" ]
then
cat $TEST/test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt
cat $TEST/test_output.txt | grep -v "wmbusmeters waiting for telegrams" | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt
diff $TEST/test_expected.txt $TEST/test_responses.txt
if [ "$?" == "0" ]
then

Wyświetl plik

@ -10,7 +10,7 @@ WMBUSMETERS_CONFIG_ROOT=tests/config1 $PROG --useconfig > $TEST/test_output.txt
if [ "$?" == "0" ]
then
cat $TEST/test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt
cat $TEST/test_output.txt | grep -v "wmbusmeters waiting for telegrams" | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt
diff $TEST/test_expected.txt $TEST/test_responses.txt
if [ "$?" == "0" ]
then

Wyświetl plik

@ -8,7 +8,7 @@ TEST=testoutput
rm -f /tmp/MyTapWater
cat simulations/simulation_c1.txt | grep '^{' | grep 76348799 | tail -n 1 > $TEST/test_expected.txt
$PROG --meterfiles --robot=json simulations/simulation_c1.txt MyTapWater multical21 76348799 ""
$PROG --meterfiles --robot=json simulations/simulation_c1.txt MyTapWater multical21 76348799 "" > /dev/null
cat /tmp/MyTapWater | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_response.txt
diff $TEST/test_expected.txt $TEST/test_response.txt
if [ "$?" == "0" ]
@ -20,7 +20,7 @@ fi
rm -rf /tmp/testmeters
mkdir /tmp/testmeters
cat simulations/simulation_c1.txt | grep '^{' | grep 76348799 | tail -n 1 > $TEST/test_expected.txt
$PROG --meterfiles=/tmp/testmeters --robot=json simulations/simulation_c1.txt MyTapWater multical21 76348799 ""
$PROG --meterfiles=/tmp/testmeters --robot=json simulations/simulation_c1.txt MyTapWater multical21 76348799 "" > /dev/null
cat /tmp/testmeters/MyTapWater | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_response.txt
diff $TEST/test_expected.txt $TEST/test_response.txt
if [ "$?" == "0" ]

Wyświetl plik

@ -9,7 +9,7 @@ TEST=testoutput
$PROG --shell='echo "$METER_JSON"' simulations/simulation_shell.txt MWW supercom587 12345678 "" > $TEST/test_output.txt
if [ "$?" == "0" ]
then
cat $TEST/test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt
cat $TEST/test_output.txt | grep -v "wmbusmeters waiting for telegrams" | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt
echo '{"media":"warm water","meter":"supercom587","name":"MWW","id":"12345678","total_m3":5.548000,"timestamp":"1111-11-11T11:11:11Z"}' > $TEST/test_expected.txt
diff $TEST/test_expected.txt $TEST/test_responses.txt
if [ "$?" == "0" ]

Wyświetl plik

@ -14,7 +14,7 @@ $PROG --robot=json simulations/simulation_t1.txt \
> $TEST/test_output.txt
if [ "$?" == "0" ]
then
cat $TEST/test_output.txt | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt
cat $TEST/test_output.txt | grep -v "wmbusmeters waiting for telegrams" | sed 's/"timestamp":"....-..-..T..:..:..Z"/"timestamp":"1111-11-11T11:11:11Z"/' > $TEST/test_responses.txt
diff $TEST/test_expected.txt $TEST/test_responses.txt
if [ "$?" == "0" ]
then