diff -up nut-2.6.5/clients/upsmon.c.foreground nut-2.6.5/clients/upsmon.c --- nut-2.6.5/clients/upsmon.c.foreground 2012-07-31 19:38:58.000000000 +0200 +++ nut-2.6.5/clients/upsmon.c 2012-09-11 17:54:55.109343036 +0200 @@ -1659,6 +1659,7 @@ static void help(const char *progname) printf(" - reload: reread configuration\n"); printf(" - stop: stop monitoring and exit\n"); printf(" -D raise debugging level\n"); + printf(" -F run in foreground, do not daemonize\n"); printf(" -h display this help\n"); printf(" -K checks POWERDOWNFLAG, sets exit code to 0 if set\n"); printf(" -p always run privileged (disable privileged parent)\n"); @@ -1873,7 +1874,7 @@ static void check_parent(void) int main(int argc, char *argv[]) { const char *prog = xbasename(argv[0]); - int i, cmd = 0, checking_flag = 0; + int i, cmd = 0, checking_flag = 0, foreground = 0; printf("Network UPS Tools %s %s\n", prog, UPS_VERSION); @@ -1884,7 +1885,7 @@ int main(int argc, char *argv[]) run_as_user = xstrdup(RUN_AS_USER); - while ((i = getopt(argc, argv, "+Dhic:f:pu:VK46")) != -1) { + while ((i = getopt(argc, argv, "+DFhic:f:pu:VK46")) != -1) { switch (i) { case 'c': if (!strncmp(optarg, "fsd", strlen(optarg))) @@ -1901,6 +1902,9 @@ int main(int argc, char *argv[]) case 'D': nut_debug_level++; break; + case 'F': + foreground = 1; + break; case 'f': free(configfile); configfile = xstrdup(optarg); @@ -1976,9 +1980,9 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } - if (nut_debug_level < 1) { + if (!foreground && nut_debug_level < 1) { background(); - } else { + } else if (nut_debug_level >= 1) { upsdebugx(1, "debug level is '%d'", nut_debug_level); } diff -up nut-2.6.5/scripts/systemd/nut-monitor.service.in.foreground nut-2.6.5/scripts/systemd/nut-monitor.service.in --- nut-2.6.5/scripts/systemd/nut-monitor.service.in.foreground 2012-09-11 17:56:05.037920175 +0200 +++ nut-2.6.5/scripts/systemd/nut-monitor.service.in 2012-09-11 17:56:05.038920183 +0200 @@ -4,9 +4,8 @@ After=local-fs.target network.target nut [Service] ExecStartPre=-/usr/bin/systemd-tmpfiles --create /etc/tmpfiles.d/nut-client.conf -ExecStart=@SBINDIR@/upsmon -PIDFile=@PIDPATH@/upsmon.pid -Type=forking +ExecStart=@SBINDIR@/upsmon -F +Type=simple [Install] WantedBy=multi-user.target diff -up nut-2.6.5/scripts/systemd/nut-server.service.in.foreground nut-2.6.5/scripts/systemd/nut-server.service.in --- nut-2.6.5/scripts/systemd/nut-server.service.in.foreground 2012-09-11 17:56:19.850042294 +0200 +++ nut-2.6.5/scripts/systemd/nut-server.service.in 2012-09-11 17:56:19.851042303 +0200 @@ -5,8 +5,8 @@ Requires=nut-driver.service Before=nut-monitor.service [Service] -ExecStart=@SBINDIR@/upsd -Type=forking +ExecStart=@SBINDIR@/upsd -F +Type=simple [Install] WantedBy=multi-user.target diff -up nut-2.6.5/server/upsd.c.foreground nut-2.6.5/server/upsd.c --- nut-2.6.5/server/upsd.c.foreground 2012-07-31 19:38:58.000000000 +0200 +++ nut-2.6.5/server/upsd.c 2012-09-11 17:54:55.109343036 +0200 @@ -819,6 +819,7 @@ static void help(const char *progname) printf(" - reload: reread configuration files\n"); printf(" - stop: stop process and exit\n"); printf(" -D raise debugging level\n"); + printf(" -F run in foreground, do not daemonize\n"); printf(" -h display this help\n"); printf(" -r <dir> chroots to <dir>\n"); printf(" -q raise log level threshold\n"); @@ -882,7 +883,7 @@ void check_perms(const char *fn) int main(int argc, char **argv) { - int i, cmd = 0; + int i, cmd = 0, foreground = 0; char *chroot_path = NULL; const char *user = RUN_AS_USER; struct passwd *new_uid = NULL; @@ -898,7 +899,7 @@ int main(int argc, char **argv) printf("Network UPS Tools %s %s\n", progname, UPS_VERSION); - while ((i = getopt(argc, argv, "+h46p:qr:i:fu:Vc:D")) != -1) { + while ((i = getopt(argc, argv, "+hF46p:qr:i:fu:Vc:D")) != -1) { switch (i) { case 'h': help(progname); @@ -936,6 +937,10 @@ int main(int argc, char **argv) nut_debug_level++; break; + case 'F': + foreground = 1; + break; + case '4': opt_af = AF_INET; break; @@ -1023,7 +1028,7 @@ int main(int argc, char **argv) /* handle upsd.users */ user_load(); - if (!nut_debug_level) { + if (!nut_debug_level && !foreground) { background(); writepid(pidfn); } else {