129 lines
4.3 KiB
Diff
129 lines
4.3 KiB
Diff
diff -up nut-2.7.1/clients/upsmon.c.foreground nut-2.7.1/clients/upsmon.c
|
|
--- nut-2.7.1/clients/upsmon.c.foreground 2013-07-26 21:41:10.000000000 +0200
|
|
+++ nut-2.7.1/clients/upsmon.c 2014-02-27 11:39:58.158784578 +0100
|
|
@@ -1645,6 +1645,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");
|
|
@@ -1859,7 +1860,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);
|
|
|
|
@@ -1870,7 +1871,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)))
|
|
@@ -1887,6 +1888,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);
|
|
@@ -1962,9 +1966,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.7.1/scripts/systemd/nut-monitor.service.in.foreground nut-2.7.1/scripts/systemd/nut-monitor.service.in
|
|
--- nut-2.7.1/scripts/systemd/nut-monitor.service.in.foreground 2014-02-27 11:39:58.141784438 +0100
|
|
+++ nut-2.7.1/scripts/systemd/nut-monitor.service.in 2014-02-27 11:39:58.152784529 +0100
|
|
@@ -4,9 +4,8 @@ After=local-fs.target network.target nut
|
|
|
|
[Service]
|
|
ExecStartPre=-/usr/bin/systemd-tmpfiles --create /usr/lib/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.7.1/scripts/systemd/nut-server.service.in.foreground nut-2.7.1/scripts/systemd/nut-server.service.in
|
|
--- nut-2.7.1/scripts/systemd/nut-server.service.in.foreground 2013-07-26 21:41:11.000000000 +0200
|
|
+++ nut-2.7.1/scripts/systemd/nut-server.service.in 2014-02-27 11:39:58.152784529 +0100
|
|
@@ -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.7.1/server/upsd.c.foreground nut-2.7.1/server/upsd.c
|
|
--- nut-2.7.1/server/upsd.c.foreground 2013-07-26 21:41:11.000000000 +0200
|
|
+++ nut-2.7.1/server/upsd.c 2014-02-27 11:39:58.153784537 +0100
|
|
@@ -827,6 +827,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");
|
|
@@ -890,7 +891,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;
|
|
@@ -906,7 +907,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);
|
|
@@ -944,6 +945,10 @@ int main(int argc, char **argv)
|
|
nut_debug_level++;
|
|
break;
|
|
|
|
+ case 'F':
|
|
+ foreground = 1;
|
|
+ break;
|
|
+
|
|
case '4':
|
|
opt_af = AF_INET;
|
|
break;
|
|
@@ -1031,7 +1036,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 {
|