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