From bd54cd187c6a4f9eff778da413a8bacf24988b36 Mon Sep 17 00:00:00 2001 From: Darold Gilles Date: Sun, 9 Jul 2017 12:00:25 +0200 Subject: [PATCH] Finalize systemd service, timer and documentation. --- README | 34 +++++++++++++++------------------- doc/pgCluu.pod | 30 ++++++++++++++---------------- pgcluu.service | 10 +++++++--- pgcluu.timer | 4 ++-- pgcluu_collectd.service | 22 ++++++++++++++-------- 5 files changed, 52 insertions(+), 48 deletions(-) diff --git a/README b/README index d80cf00..d533716 100644 --- a/README +++ b/README @@ -96,30 +96,26 @@ USAGE not already exits. Using systemd unit files - pgcluu comes with a systemd service file pgcluu.service and a timer unit - file pgcluu.timer. The last one will trigger the first one periodically. - This is sample files that you may want to adapt following your needs. + pgcluu comes with systemd service files: - Default for pgcluu.service has been set to end after 3 minutes with the - --end-after=3M option. Edit the file to set path to your $OUTPUTDIR and - $STATDIR, and $PGPASSWORD. Change if needed how long the collect will - last. + - pgcluu_collectd.service: execute pgcluu_collectd as a daemon to collect statistics. + - pgcluu.service: execute pgcluu to generate reports. + - pgcluu.timer: run periodically pgcluu.service - Default for pgcluu.timer has been set to start pgcluu.service every - three hours with the OnUnitActiveSec=3h. Again, change it if needed. - Refer to man:systemd.timer(5) for more options. + This is sample files that you may want to adapt to your Linux + distribution or your needs. To install them after editing use commands + below: - Once the two files have been edited accordingly, copy them in your - system systemd directory, /etc/systemd/system. As root, start and enable - the timer: + cp pgcluu_collectd.service /usr/lib/systemd/system/ + cp pgcluu.service /usr/lib/systemd/system/ + cp pgcluu.timer /usr/lib/systemd/system/ - systemctl start pgcluu.timer + systemctl daemon-reload + systemctl enable pgcluu_collectd.service + systemctl enable pgcluu.service systemctl enable pgcluu.timer - - You can at anytime see if the timer is still active with the following - command: - - systemctl list-timers + systemctl start pgcluu_collectd.service + systemctl start pgcluu.timer COLLECTING STATISTICS To generate reports about your PostgreSQL Cluster Utilization you must diff --git a/doc/pgCluu.pod b/doc/pgCluu.pod index 5719f46..3b3dac1 100644 --- a/doc/pgCluu.pod +++ b/doc/pgCluu.pod @@ -103,27 +103,25 @@ generated into the output directory if those files does not already exits. =head3 Using systemd unit files -pgcluu comes with a systemd service file pgcluu.service and a timer unit file -pgcluu.timer. The last one will trigger the first one periodically. This is -sample files that you may want to adapt following your needs. +pgcluu comes with systemd service files: -Default for pgcluu.service has been set to end after 3 minutes with the ---end-after=3M option. Edit the file to set path to your $OUTPUTDIR and -$STATDIR, and $PGPASSWORD. Change if needed how long the collect will last. + - pgcluu_collectd.service: execute pgcluu_collectd as a daemon to collect statistics. + - pgcluu.service: execute pgcluu to generate reports. + - pgcluu.timer: run periodically pgcluu.service -Default for pgcluu.timer has been set to start pgcluu.service every three -hours with the OnUnitActiveSec=3h. Again, change it if needed. Refer to -man:systemd.timer(5) for more options. +This is sample files that you may want to adapt to your Linux distribution or +your needs. To install them after editing use commands below: -Once the two files have been edited accordingly, copy them in your system -systemd directory, /etc/systemd/system. As root, start and enable the timer: + cp pgcluu_collectd.service /usr/lib/systemd/system/ + cp pgcluu.service /usr/lib/systemd/system/ + cp pgcluu.timer /usr/lib/systemd/system/ - systemctl start pgcluu.timer + systemctl daemon-reload + systemctl enable pgcluu_collectd.service + systemctl enable pgcluu.service systemctl enable pgcluu.timer - -You can at anytime see if the timer is still active with the following command: - - systemctl list-timers + systemctl start pgcluu_collectd.service + systemctl start pgcluu.timer =head1 COLLECTING STATISTICS diff --git a/pgcluu.service b/pgcluu.service index 339d2b3..5804f32 100644 --- a/pgcluu.service +++ b/pgcluu.service @@ -7,15 +7,19 @@ [Unit] -Description=Postgresql performance and auditing +Description=Postgresql performance and auditing reporting Documentation=man:pgcluu(1) [Service] +PermissionsStartOnly=true User=postgres Environment=STATDIR=/var/lib/pgcluu/data Environment=REPORTDIR=/var/lib/pgcluu/report -ExecStartPre=-/usr/bin/find ${REPORTDIR} -mindepth 1 -type f -delete -ExecStart=/usr/local/bin/pgcluu -o ${REPORTDIR} ${STATDIR} +ExecStartPre=-/bin/mkdir -p $REPORTDIR +ExecStartPre=-/bin/chown postgres: $REPORTDIR +ExecStart=/usr/local/bin/pgcluu -o $REPORTDIR $STATDIR +[Install] +WantedBy=multi-user.target diff --git a/pgcluu.timer b/pgcluu.timer index bfa6fd2..0d5a1c6 100644 --- a/pgcluu.timer +++ b/pgcluu.timer @@ -2,8 +2,8 @@ Description=Run periodically pgcluu.service [Timer] -OnBootSec=15min -OnUnitActiveSec=1h +OnBootSec=5min +OnUnitActiveSec=5min [Install] WantedBy=timers.target diff --git a/pgcluu_collectd.service b/pgcluu_collectd.service index d34f5f8..338cbe1 100644 --- a/pgcluu_collectd.service +++ b/pgcluu_collectd.service @@ -1,25 +1,31 @@ # Start script to run pgcluu_collectd as daemon # -# Feel free to modify the name of the PostgreSQL service following +# Feel free to modify the name of the PostgreSQL service and the path to following # your installation. # -# For more info about custom unit files, see -# http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F - - [Unit] -Description=Postgresql performance and auditing +Description=Postgresql performance and auditing statistics collecting Documentation=man:pgcluu(1) After=postgresql-9.x.service Wants=postgresql-9.x.service [Service] +Type=forking +PermissionsStartOnly=true User=postgres Environment=STATDIR=/var/lib/pgcluu/data -ExecStart=/usr/local/bin/pgcluu_collectd -D $STATDIR -ExecReload=/bin/kill -HUP $MAINPID +Environment=PIDFILE=/var/run/postgresql/pgcluu_collectd.pid +ExecStartPre=-/bin/mkdir -p $STATDIR +ExecStartPre=-/bin/chown postgres: $STATDIR +ExecStart=/usr/local/bin/pgcluu_collectd --daemonize --rotate-daily --pid-file $PIDFILE $STATDIR +ExecStop=/usr/local/bin/pgcluu_collectd -k --pid-file $PIDFILE KillMode=process Restart=on-failure +RestartSec=60s +PIDFile=/var/run/postgresql/pgcluu_collectd.pid + +[Install] +WantedBy=multi-user.target