|
|
135b98 |
autofs-5.1.4 - add systemd service command line option
|
|
|
135b98 |
|
|
|
135b98 |
From: Ian Kent <raven@themaw.net>
|
|
|
135b98 |
|
|
|
135b98 |
When run as a systemd service using the systemd notification method to
|
|
|
135b98 |
synchronise startup, logging should be done to syslog so the log entry
|
|
|
135b98 |
format is consistent between daemon and systemd usage.
|
|
|
135b98 |
|
|
|
135b98 |
So, rather than run use the forground option, add an option to tell
|
|
|
135b98 |
the automounter it's being run as a systemd service and use syslog
|
|
|
135b98 |
for logging when its present on the command line.
|
|
|
135b98 |
|
|
|
135b98 |
Signed-off-by: Ian Kent <raven@themaw.net>
|
|
|
135b98 |
---
|
|
|
135b98 |
CHANGELOG | 1 +
|
|
|
135b98 |
daemon/automount.c | 22 +++++++++++++++++++---
|
|
|
135b98 |
include/automount.h | 1 +
|
|
|
135b98 |
man/automount.8 | 4 ++++
|
|
|
135b98 |
samples/autofs.service.in | 2 +-
|
|
|
135b98 |
5 files changed, 26 insertions(+), 4 deletions(-)
|
|
|
135b98 |
|
|
|
135b98 |
--- autofs-5.1.4.orig/CHANGELOG
|
|
|
135b98 |
+++ autofs-5.1.4/CHANGELOG
|
|
|
135b98 |
@@ -43,6 +43,7 @@ xx/xx/2018 autofs-5.1.5
|
|
|
135b98 |
- update build info with systemd.
|
|
|
135b98 |
- use flags for startup boolean options.
|
|
|
135b98 |
- move close stdio descriptors to become_daemon().
|
|
|
135b98 |
+- add systemd service command line option.
|
|
|
135b98 |
|
|
|
135b98 |
19/12/2017 autofs-5.1.4
|
|
|
135b98 |
- fix spec file url.
|
|
|
135b98 |
--- autofs-5.1.4.orig/daemon/automount.c
|
|
|
135b98 |
+++ autofs-5.1.4/daemon/automount.c
|
|
|
135b98 |
@@ -1210,13 +1210,21 @@ static void become_daemon(unsigned int f
|
|
|
135b98 |
}
|
|
|
135b98 |
|
|
|
135b98 |
/* Detach from foreground process */
|
|
|
135b98 |
- if (flags & DAEMON_FLAGS_FOREGROUND) {
|
|
|
135b98 |
+ if (flags & DAEMON_FLAGS_FOREGROUND &&
|
|
|
135b98 |
+ !(flags & DAEMON_FLAGS_SYSTEMD_SERVICE)) {
|
|
|
135b98 |
if ((flags & DAEMON_FLAGS_CHECK_DAEMON) && !aquire_flag_file()) {
|
|
|
135b98 |
fprintf(stderr, "%s: program is already running.\n",
|
|
|
135b98 |
program);
|
|
|
135b98 |
exit(1);
|
|
|
135b98 |
}
|
|
|
135b98 |
log_to_stderr();
|
|
|
135b98 |
+ } else if (flags & DAEMON_FLAGS_SYSTEMD_SERVICE) {
|
|
|
135b98 |
+ if ((flags & DAEMON_FLAGS_CHECK_DAEMON) && !aquire_flag_file()) {
|
|
|
135b98 |
+ fprintf(stderr, "%s: program is already running.\n",
|
|
|
135b98 |
+ program);
|
|
|
135b98 |
+ exit(1);
|
|
|
135b98 |
+ }
|
|
|
135b98 |
+ open_log();
|
|
|
135b98 |
} else {
|
|
|
135b98 |
int nullfd;
|
|
|
135b98 |
|
|
|
135b98 |
@@ -1925,6 +1933,8 @@ static void usage(void)
|
|
|
135b98 |
" -d --debug log debuging info\n"
|
|
|
135b98 |
" -Dvariable=value, --define variable=value\n"
|
|
|
135b98 |
" define global macro variable\n"
|
|
|
135b98 |
+ " -S --systemd-service\n"
|
|
|
135b98 |
+ " run automounter as a systemd service\n"
|
|
|
135b98 |
" -f --foreground do not fork into background\n"
|
|
|
135b98 |
" -r --random-multimount-selection\n"
|
|
|
135b98 |
" use ramdom replicated server selection\n"
|
|
|
135b98 |
@@ -2190,7 +2200,7 @@ int main(int argc, char *argv[])
|
|
|
135b98 |
time_t timeout;
|
|
|
135b98 |
time_t age = monotonic_time(NULL);
|
|
|
135b98 |
struct rlimit rlim;
|
|
|
135b98 |
- const char *options = "+hp:t:vmdD:fVrO:l:n:CFM";
|
|
|
135b98 |
+ const char *options = "+hp:t:vmdD:SfVrO:l:n:CFM";
|
|
|
135b98 |
static const struct option long_options[] = {
|
|
|
135b98 |
{"help", 0, 0, 'h'},
|
|
|
135b98 |
{"pid-file", 1, 0, 'p'},
|
|
|
135b98 |
@@ -2198,6 +2208,7 @@ int main(int argc, char *argv[])
|
|
|
135b98 |
{"verbose", 0, 0, 'v'},
|
|
|
135b98 |
{"debug", 0, 0, 'd'},
|
|
|
135b98 |
{"define", 1, 0, 'D'},
|
|
|
135b98 |
+ {"systemd-service", 0, 0, 'S'},
|
|
|
135b98 |
{"foreground", 0, 0, 'f'},
|
|
|
135b98 |
{"random-multimount-selection", 0, 0, 'r'},
|
|
|
135b98 |
{"negative-timeout", 1, 0, 'n'},
|
|
|
135b98 |
@@ -2266,6 +2277,10 @@ int main(int argc, char *argv[])
|
|
|
135b98 |
macro_parse_globalvar(optarg);
|
|
|
135b98 |
break;
|
|
|
135b98 |
|
|
|
135b98 |
+ case 'S':
|
|
|
135b98 |
+ flags |= DAEMON_FLAGS_SYSTEMD_SERVICE;
|
|
|
135b98 |
+ break;
|
|
|
135b98 |
+
|
|
|
135b98 |
case 'f':
|
|
|
135b98 |
flags |= DAEMON_FLAGS_FOREGROUND;
|
|
|
135b98 |
break;
|
|
|
135b98 |
@@ -2653,7 +2668,8 @@ int main(int argc, char *argv[])
|
|
|
135b98 |
}
|
|
|
135b98 |
|
|
|
135b98 |
#ifdef WITH_SYSTEMD
|
|
|
135b98 |
- sd_notify(1, "READY=1");
|
|
|
135b98 |
+ if (flags & DAEMON_FLAGS_SYSTEMD_SERVICE)
|
|
|
135b98 |
+ sd_notify(1, "READY=1");
|
|
|
135b98 |
#endif
|
|
|
135b98 |
|
|
|
135b98 |
state_mach_thid = pthread_self();
|
|
|
135b98 |
--- autofs-5.1.4.orig/include/automount.h
|
|
|
135b98 |
+++ autofs-5.1.4/include/automount.h
|
|
|
135b98 |
@@ -67,6 +67,7 @@
|
|
|
135b98 |
#endif
|
|
|
135b98 |
|
|
|
135b98 |
#define DAEMON_FLAGS_FOREGROUND 0x0001
|
|
|
135b98 |
+#define DAEMON_FLAGS_SYSTEMD_SERVICE 0x0002
|
|
|
135b98 |
#define DAEMON_FLAGS_HAVE_GLOBAL_OPTIONS 0x0004
|
|
|
135b98 |
#define DAEMON_FLAGS_GHOST 0x0008
|
|
|
135b98 |
#define DAEMON_FLAGS_CHECK_DAEMON 0x0010
|
|
|
135b98 |
--- autofs-5.1.4.orig/man/automount.8
|
|
|
135b98 |
+++ autofs-5.1.4/man/automount.8
|
|
|
135b98 |
@@ -57,6 +57,10 @@ Define a global macro substitution varia
|
|
|
135b98 |
are over-ridden macro definitions of the same name specified in
|
|
|
135b98 |
mount entries.
|
|
|
135b98 |
.TP
|
|
|
135b98 |
+.I \-S, \-\-systemd-service
|
|
|
135b98 |
+Used when running the automounter as a systemd service to ensure log entry
|
|
|
135b98 |
+format is consistent with the log entry format when running as a daemon.
|
|
|
135b98 |
+.TP
|
|
|
135b98 |
.I "\-f, \-\-foreground"
|
|
|
135b98 |
Run the daemon in the foreground and log to stderr instead of syslog."
|
|
|
135b98 |
.TP
|
|
|
135b98 |
--- autofs-5.1.4.orig/samples/autofs.service.in
|
|
|
135b98 |
+++ autofs-5.1.4/samples/autofs.service.in
|
|
|
135b98 |
@@ -6,7 +6,7 @@ Wants=network-online.target rpc-statd.se
|
|
|
135b98 |
[Service]
|
|
|
135b98 |
Type=notify
|
|
|
135b98 |
EnvironmentFile=-@@autofsconfdir@@/autofs
|
|
|
135b98 |
-ExecStart=@@sbindir@@/automount $OPTIONS --foreground --dont-check-daemon
|
|
|
135b98 |
+ExecStart=@@sbindir@@/automount $OPTIONS --systemd-service --dont-check-daemon
|
|
|
135b98 |
ExecReload=/usr/bin/kill -HUP $MAINPID
|
|
|
135b98 |
KillMode=process
|
|
|
135b98 |
TimeoutSec=180
|