From 4482bde0673fe1e548060a5c7ef6f58cf43209c3 Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Mon, 7 Jan 2019 02:07:01 +0100 Subject: [PATCH] pmlogger_daily: add systemd timers as cron alternative The timer and service files are installed by default with ENABLE_SYSTEMD. crontab.docker is kept as-is. Signed-off-by: David Disseldorp --- src/pmlogger/GNUmakefile | 32 ++++++++++++++++++++++++++-- src/pmlogger/pmlogger_daily.service.in | 8 +++++++ src/pmlogger/pmlogger_daily.timer | 8 +++++++ src/pmlogger/pmlogger_daily_check.service.in | 8 +++++++ src/pmlogger/pmlogger_daily_check.timer | 9 ++++++++ src/pmlogger/pmlogger_daily_poll.service.in | 8 +++++++ src/pmlogger/pmlogger_daily_poll.timer | 8 +++++++ 7 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 src/pmlogger/pmlogger_daily.service.in create mode 100644 src/pmlogger/pmlogger_daily.timer create mode 100644 src/pmlogger/pmlogger_daily_check.service.in create mode 100644 src/pmlogger/pmlogger_daily_check.timer create mode 100644 src/pmlogger/pmlogger_daily_poll.service.in create mode 100644 src/pmlogger/pmlogger_daily_poll.timer Index: pcp/src/pmlogger/GNUmakefile =================================================================== --- pcp.orig/src/pmlogger/GNUmakefile +++ pcp/src/pmlogger/GNUmakefile @@ -20,7 +20,9 @@ SUBDIRS = src OTHERS = pmnewlog.sh control rc_pmlogger \ pmlogger_daily.sh pmlogger_check.sh pmlogger_merge.sh pmlogmv.sh \ pmlogger_daily_report.sh pmlogger_rewrite.sh -LDIRT = crontab crontab.docker crontab.daily_report pmlogger.service +LDIRT = crontab crontab.docker crontab.daily_report pmlogger.service \ + pmlogger_daily.service pmlogger_daily_poll.service \ + pmlogger_daily_check.service ifeq ($(TARGET_OS),linux) CRONTAB_USER = $(PCP_USER) @@ -31,7 +33,7 @@ CRONTAB_PATH = $(PCP_SYSCONF_DIR)/pmlogg endif CRONTAB_DAILY_REPORT_PATH = $(CRONTAB_PATH)-daily-report -default:: crontab crontab.docker pmlogger.service crontab.daily_report +default:: $(LDIRT) default:: $(SUBDIRS) $(SUBDIRS_MAKERULE) @@ -57,6 +59,12 @@ endif $(INSTALL) -m 755 rc_pmlogger $(PCP_RC_DIR)/pmlogger ifeq ($(ENABLE_SYSTEMD),true) $(INSTALL) -m 644 pmlogger.service $(PCP_SYSTEMDUNIT_DIR)/pmlogger.service + $(INSTALL) -m 644 pmlogger_daily.timer $(PCP_SYSTEMDUNIT_DIR)/pmlogger_daily.timer + $(INSTALL) -m 644 pmlogger_daily.service $(PCP_SYSTEMDUNIT_DIR)/pmlogger_daily.service + $(INSTALL) -m 644 pmlogger_daily_poll.timer $(PCP_SYSTEMDUNIT_DIR)/pmlogger_daily_poll.timer + $(INSTALL) -m 644 pmlogger_daily_poll.service $(PCP_SYSTEMDUNIT_DIR)/pmlogger_daily_poll.service + $(INSTALL) -m 644 pmlogger_daily_check.timer $(PCP_SYSTEMDUNIT_DIR)/pmlogger_daily_check.timer + $(INSTALL) -m 644 pmlogger_daily_check.service $(PCP_SYSTEMDUNIT_DIR)/pmlogger_daily_check.service endif $(INSTALL) -m 775 -o $(PCP_USER) -g $(PCP_GROUP) -d $(PCP_LOG_DIR)/pmlogger $(INSTALL) -m 775 -o $(PCP_USER) -g $(PCP_GROUP) -d $(PCP_TMP_DIR)/pmlogger @@ -68,7 +76,9 @@ ifeq ($(TARGET_OS),linux) $(INSTALL) -m 755 -d $(PCP_LOG_DIR)/pmlogger $(INSTALL) -m 1777 -d $(PCP_TMP_DIR)/pmlogger endif +ifneq ($(ENABLE_SYSTEMD),true) $(INSTALL) -m 644 crontab $(CRONTAB_PATH) +endif $(INSTALL) -m 644 utilproc.sh $(PCP_SHARE_DIR)/lib/utilproc.sh $(INSTALL) -m 755 pmlogger_daily_report.sh $(PCP_BINADM_DIR)/pmlogger_daily_report$(SHELLSUFFIX) $(INSTALL) -m 644 crontab.daily_report $(CRONTAB_DAILY_REPORT_PATH) @@ -86,6 +96,24 @@ pmlogger.service : pmlogger.service.in -e 's;@PCP_RUN_DIR@;'$(PCP_RUN_DIR)';' \ # END +pmlogger_daily.service : pmlogger_daily.service.in + $(SED) <$< >$@ \ + -e 's;@PCP_BINADM_DIR@;'$(PCP_BINADM_DIR)';' \ + -e 's;@PCP_USER@;'$(PCP_USER)';' \ + # END + +pmlogger_daily_poll.service : pmlogger_daily_poll.service.in + $(SED) <$< >$@ \ + -e 's;@PCP_BINADM_DIR@;'$(PCP_BINADM_DIR)';' \ + -e 's;@PCP_USER@;'$(PCP_USER)';' \ + # END + +pmlogger_daily_check.service : pmlogger_daily_check.service.in + $(SED) <$< >$@ \ + -e 's;@PCP_BINADM_DIR@;'$(PCP_BINADM_DIR)';' \ + -e 's;@PCP_USER@;'$(PCP_USER)';' \ + # END + crontab : crontab.in $(SED) -e 's;@user@;'$(CRONTAB_USER)';' -e 's;@path@;'$(PCP_BINADM_DIR)';' $< > $@ Index: pcp/src/pmlogger/pmlogger_daily.service.in =================================================================== --- /dev/null +++ pcp/src/pmlogger/pmlogger_daily.service.in @@ -0,0 +1,8 @@ +[Unit] +Description=Process archive logs +Documentation=man:pmlogger(1) + +[Service] +Type=oneshot +ExecStart=@PCP_BINADM_DIR@/pmlogger_daily +User=@PCP_USER@ Index: pcp/src/pmlogger/pmlogger_daily.timer =================================================================== --- /dev/null +++ pcp/src/pmlogger/pmlogger_daily.timer @@ -0,0 +1,8 @@ +[Unit] +Description=Daily processing of archive logs + +[Timer] +OnCalendar=*-*-* 00:10:00 + +[Install] +WantedBy=timers.target Index: pcp/src/pmlogger/pmlogger_daily_check.service.in =================================================================== --- /dev/null +++ pcp/src/pmlogger/pmlogger_daily_check.service.in @@ -0,0 +1,8 @@ +[Unit] +Description=Check pmlogger instances are running +Documentation=man:pmlogger(1) + +[Service] +Type=oneshot +ExecStart=@PCP_BINADM_DIR@/pmlogger_daily -C +User=@PCP_USER@ Index: pcp/src/pmlogger/pmlogger_daily_check.timer =================================================================== --- /dev/null +++ pcp/src/pmlogger/pmlogger_daily_check.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Half-hourly check of pmlogger instances + +[Timer] +OnCalendar=*-*-* *:25:00 +OnCalendar=*-*-* *:55:00 + +[Install] +WantedBy=timers.target Index: pcp/src/pmlogger/pmlogger_daily_poll.service.in =================================================================== --- /dev/null +++ pcp/src/pmlogger/pmlogger_daily_poll.service.in @@ -0,0 +1,8 @@ +[Unit] +Description=Poll log processing +Documentation=man:pmlogger(1) + +[Service] +Type=oneshot +ExecStart=@PCP_BINADM_DIR@/pmlogger_daily -p +User=@PCP_USER@ Index: pcp/src/pmlogger/pmlogger_daily_poll.timer =================================================================== --- /dev/null +++ pcp/src/pmlogger/pmlogger_daily_poll.timer @@ -0,0 +1,8 @@ +[Unit] +Description=Hourly polling of log processing + +[Timer] +OnCalendar=*-*-* *:30:00 + +[Install] +WantedBy=timers.target