kopia lustrzana https://github.com/weetmuts/wmbusmeters
More work on running as daemon.
rodzic
54ffc41a9f
commit
b68cadfdc8
|
@ -96,7 +96,7 @@ Type=simple
|
||||||
#Restart=always
|
#Restart=always
|
||||||
RestartSec=1
|
RestartSec=1
|
||||||
User=wmbusmeters
|
User=wmbusmeters
|
||||||
ExecStart=/usr/sbin/wmbusmetersd
|
ExecStart=/usr/bin/wmbusmeters --useconfig
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|
|
@ -165,7 +165,6 @@ void startUsingCommandline(CommandLine *cmdline)
|
||||||
auto output = unique_ptr<Printer>(new Printer(cmdline->json, cmdline->fields,
|
auto output = unique_ptr<Printer>(new Printer(cmdline->json, cmdline->fields,
|
||||||
cmdline->separator, cmdline->meterfiles, cmdline->meterfiles_dir,
|
cmdline->separator, cmdline->meterfiles, cmdline->meterfiles_dir,
|
||||||
cmdline->shells));
|
cmdline->shells));
|
||||||
|
|
||||||
vector<unique_ptr<Meter>> meters;
|
vector<unique_ptr<Meter>> meters;
|
||||||
|
|
||||||
if (cmdline->meters.size() > 0) {
|
if (cmdline->meters.size() > 0) {
|
||||||
|
@ -232,6 +231,7 @@ void startUsingCommandline(CommandLine *cmdline)
|
||||||
wmbus->simulate();
|
wmbus->simulate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notice("wmbusmeters waiting for telegrams\n");
|
||||||
manager->waitForStop();
|
manager->waitForStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,10 +265,10 @@ void startDaemon()
|
||||||
setlogmask(LOG_UPTO (LOG_NOTICE));
|
setlogmask(LOG_UPTO (LOG_NOTICE));
|
||||||
openlog("wmbusmetersd", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
|
openlog("wmbusmetersd", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
|
||||||
|
|
||||||
syslog(LOG_NOTICE, "wmbusmeters started by User %d", getuid ());
|
|
||||||
|
|
||||||
enableSyslog();
|
enableSyslog();
|
||||||
|
|
||||||
|
notice("wmbusmeters started by user %d\n", getuid ());
|
||||||
|
|
||||||
// Create a new SID for the daemon
|
// Create a new SID for the daemon
|
||||||
pid_t sid = setsid();
|
pid_t sid = setsid();
|
||||||
if (sid < 0) {
|
if (sid < 0) {
|
||||||
|
|
|
@ -64,6 +64,9 @@ void Printer::printFiles(Meter *meter, string &human_readable, string &fields, s
|
||||||
memset(filename, 0, sizeof(filename));
|
memset(filename, 0, sizeof(filename));
|
||||||
snprintf(filename, 127, "%s/%s", meterfiles_dir_.c_str(), meter->name().c_str());
|
snprintf(filename, 127, "%s/%s", meterfiles_dir_.c_str(), meter->name().c_str());
|
||||||
output = fopen(filename, "w");
|
output = fopen(filename, "w");
|
||||||
|
if (!output) {
|
||||||
|
warning("Could not open file \"%s\" for writing!\n", filename);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json_) {
|
if (json_) {
|
||||||
|
|
22
src/util.cc
22
src/util.cc
|
@ -192,6 +192,28 @@ bool isLogTelegramsEnabled() {
|
||||||
return log_telegrams_enabled_;
|
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, ...) {
|
void warning(const char* fmt, ...) {
|
||||||
if (warning_enabled_) {
|
if (warning_enabled_) {
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
|
@ -44,6 +44,8 @@ void error(const char* fmt, ...);
|
||||||
void verbose(const char* fmt, ...);
|
void verbose(const char* fmt, ...);
|
||||||
void debug(const char* fmt, ...);
|
void debug(const char* fmt, ...);
|
||||||
void warning(const char* fmt, ...);
|
void warning(const char* fmt, ...);
|
||||||
|
void info(const char* fmt, ...);
|
||||||
|
void notice(const char* fmt, ...);
|
||||||
|
|
||||||
void warningSilenced(bool b);
|
void warningSilenced(bool b);
|
||||||
void verboseEnabled(bool b);
|
void verboseEnabled(bool b);
|
||||||
|
|
|
@ -13,9 +13,10 @@ $PROG --robot=json simulations/simulation_c1.txt \
|
||||||
Vadden multical21 44556677 "" \
|
Vadden multical21 44556677 "" \
|
||||||
MyElectricity omnipower 15947107 "" \
|
MyElectricity omnipower 15947107 "" \
|
||||||
> $TEST/test_output.txt
|
> $TEST/test_output.txt
|
||||||
|
|
||||||
if [ "$?" == "0" ]
|
if [ "$?" == "0" ]
|
||||||
then
|
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
|
diff $TEST/test_expected.txt $TEST/test_responses.txt
|
||||||
if [ "$?" == "0" ]
|
if [ "$?" == "0" ]
|
||||||
then
|
then
|
||||||
|
|
|
@ -10,7 +10,7 @@ WMBUSMETERS_CONFIG_ROOT=tests/config1 $PROG --useconfig > $TEST/test_output.txt
|
||||||
|
|
||||||
if [ "$?" == "0" ]
|
if [ "$?" == "0" ]
|
||||||
then
|
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
|
diff $TEST/test_expected.txt $TEST/test_responses.txt
|
||||||
if [ "$?" == "0" ]
|
if [ "$?" == "0" ]
|
||||||
then
|
then
|
||||||
|
|
|
@ -8,7 +8,7 @@ TEST=testoutput
|
||||||
|
|
||||||
rm -f /tmp/MyTapWater
|
rm -f /tmp/MyTapWater
|
||||||
cat simulations/simulation_c1.txt | grep '^{' | grep 76348799 | tail -n 1 > $TEST/test_expected.txt
|
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
|
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
|
diff $TEST/test_expected.txt $TEST/test_response.txt
|
||||||
if [ "$?" == "0" ]
|
if [ "$?" == "0" ]
|
||||||
|
@ -20,7 +20,7 @@ fi
|
||||||
rm -rf /tmp/testmeters
|
rm -rf /tmp/testmeters
|
||||||
mkdir /tmp/testmeters
|
mkdir /tmp/testmeters
|
||||||
cat simulations/simulation_c1.txt | grep '^{' | grep 76348799 | tail -n 1 > $TEST/test_expected.txt
|
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
|
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
|
diff $TEST/test_expected.txt $TEST/test_response.txt
|
||||||
if [ "$?" == "0" ]
|
if [ "$?" == "0" ]
|
||||||
|
|
|
@ -9,7 +9,7 @@ TEST=testoutput
|
||||||
$PROG --shell='echo "$METER_JSON"' simulations/simulation_shell.txt MWW supercom587 12345678 "" > $TEST/test_output.txt
|
$PROG --shell='echo "$METER_JSON"' simulations/simulation_shell.txt MWW supercom587 12345678 "" > $TEST/test_output.txt
|
||||||
if [ "$?" == "0" ]
|
if [ "$?" == "0" ]
|
||||||
then
|
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
|
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
|
diff $TEST/test_expected.txt $TEST/test_responses.txt
|
||||||
if [ "$?" == "0" ]
|
if [ "$?" == "0" ]
|
||||||
|
|
|
@ -14,7 +14,7 @@ $PROG --robot=json simulations/simulation_t1.txt \
|
||||||
> $TEST/test_output.txt
|
> $TEST/test_output.txt
|
||||||
if [ "$?" == "0" ]
|
if [ "$?" == "0" ]
|
||||||
then
|
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
|
diff $TEST/test_expected.txt $TEST/test_responses.txt
|
||||||
if [ "$?" == "0" ]
|
if [ "$?" == "0" ]
|
||||||
then
|
then
|
||||||
|
|
Ładowanie…
Reference in New Issue