diff --git a/pmm-server-user.service b/pmm-server-user.service new file mode 100644 index 000000000..ce74e515d --- /dev/null +++ b/pmm-server-user.service @@ -0,0 +1,29 @@ +[Unit] +Description=pmm-server +Wants=network-online.target +After=network-online.target +After=nss-user-lookup.target nss-lookup.target +After=time-sync.target + +[Service] +Type=simple + +# set environment for this unit +Environment=PMM_PUBLIC_PORT=8443 +Environment=PMM_VOLUME_NAME=%N +Environment=PMM_TAG=2.27.0 +Environment=PMM_IMAGE=docker.io/percona/pmm-server +Environment=PMM_ENV_FILE=%h/.config/pmm-server/pmm-server.env + +# optional env file that could overide previous env settings for this unit +EnvironmentFile=-%h/.config/pmm-server/env + +ExecStartPre=/usr/bin/bash -c '/usr/bin/podman stop -t 10 %N; /usr/bin/podman rm -f %N || true' +ExecStart=/usr/bin/podman run --rm --name %N -p ${PMM_PUBLIC_PORT}:443/tcp --ulimit=host --volume=${PMM_VOLUME_NAME}:/srv --env-file=${PMM_ENV_FILE} --health-cmd=none --health-interval=disable ${PMM_IMAGE}:${PMM_TAG} +ExecStop=/usr/bin/podman stop -t 10 %N +ExecStopPost=/usr/bin/podman stop -t 10 `%N` +Restart=on-failure +RestartSec=20 + +[Install] +WantedBy=default.target diff --git a/pmm-server.env b/pmm-server.env new file mode 100644 index 000000000..13c19338f --- /dev/null +++ b/pmm-server.env @@ -0,0 +1,10 @@ +# env file passed to the container +# full list of environment variables: +# https://www.percona.com/doc/percona-monitoring-and-management/2.x/setting-up/server/docker.html#environment-variables + +# keep updates disabled +# do image replacement instead (update the tag and restart the service) +DISABLE_UPDATES=1 + +# Enable DBaaS feature +#ENABLE_DBAAS=1 diff --git a/pmm-server.service b/pmm-server.service new file mode 100644 index 000000000..0a790bf28 --- /dev/null +++ b/pmm-server.service @@ -0,0 +1,31 @@ +[Unit] +Description=pmm-server +Wants=network-online.target +After=network-online.target +After=nss-user-lookup.target nss-lookup.target +After=time-sync.target + +[Service] +Type=simple +User=pmm-server +Group=pmm + +# set environment for this unit +Environment=PMM_PUBLIC_PORT=8443 +Environment=PMM_VOLUME_NAME=%N +Environment=PMM_TAG=2.27.0 +Environment=PMM_IMAGE=docker.io/percona/pmm-server +Environment=PMM_ENV_FILE=%E/pmm-server/pmm-server.env + +# optional env file that could overide previous env settings for this unit +EnvironmentFile=-%E/pmm-server/env + +ExecStartPre=/usr/bin/bash -c '/usr/bin/podman stop -t 10 %N; /usr/bin/podman rm -f %N || true' +ExecStart=/usr/bin/podman run --rm --name %N -p ${PMM_PUBLIC_PORT}:443/tcp --ulimit=host --volume=${PMM_VOLUME_NAME}:/srv --env-file=${PMM_ENV_FILE} ${PMM_IMAGE}:${PMM_TAG} +ExecStop=/usr/bin/podman stop -t 10 %N +ExecStopPost=/usr/bin/podman stop -t 10 `%N` +Restart=on-failure +RestartSec=20 + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/rhel/SPECS/pmm-server.spec b/rhel/SPECS/pmm-server.spec index 7b139791a..e023ebe02 100644 --- a/rhel/SPECS/pmm-server.spec +++ b/rhel/SPECS/pmm-server.spec @@ -10,15 +10,15 @@ %define release 26 %define rpm_release %{release}.%{build_timestamp}.%{shortcommit}%{?dist} -Name: %{repo} -Version: %{version} -Release: %{rpm_release} -Summary: Percona Monitoring and Management Server +Name: %{repo} +Version: %{version} +Release: %{rpm_release} +Summary: Percona Monitoring and Management Server -License: AGPLv3 -URL: https://%{provider} -Source0: https://%{provider}/archive/%{commit}/%{repo}-%{shortcommit}.tar.gz -Source1: https://%{pmm_provider}/archive/%{pmm_commit}/%{pmm_repo}-%{pmm_shortcommit}.tar.gz +License: AGPLv3 +URL: https://%{provider} +Source0: https://%{provider}/archive/%{commit}/%{repo}-%{shortcommit}.tar.gz +Source1: https://%{pmm_provider}/archive/%{pmm_commit}/%{pmm_repo}-%{pmm_shortcommit}.tar.gz BuildArch: noarch BuildRequires: openssl @@ -27,6 +27,22 @@ BuildRequires: openssl Percona Monitoring and Management (PMM) Server. See the PMM docs for more information. +%package systemd +Version: %{version} +Release: %{rpm_release} +Summary: SystemD service for Percona Monitoring and Management Server + +License: AGPLv3 +URL: https://%{provider} + +BuildArch: noarch +Requires: podman systemd shadow-utils +BuildRequires: systemd-rpm-macros + +%description systemd +SystemD service to run Percona Monitoring and Management (PMM) Server. +It runs podman to manage PMM. +See the PMM docs for more information. %prep %setup -q -n %{repo}-%{commit} @@ -51,6 +67,32 @@ cp -pav ./installation-wizard/build %{buildroot}%{_datadir}/%{name}/installation cp -pav ./%{pmm_repo}-%{pmm_commit}/api/swagger %{buildroot}%{_datadir}/%{name}/swagger rm -rf %{pmm_repo}-%{pmm_commit} +# pmm-server-systemd package +install -D -m 0644 pmm-server.service %{buildroot}/%{_unitdir}/pmm-server.service +install -D -p -m 0644 pmm-server.env %{buildroot}/%{_sysconfdir}/%{repo}/pmm-server.env + +%pre systemd + +# use newusers util to create user and group to assign subuid/subguid +# newusers pw_name:pw_passwd:pw_uid:pw_gid:pw_gecos:pw_dir:pw_shel +getent passwd pmm-server >/dev/null >/dev/null || echo "pmm-server:::pmm::/home/pmm-server:/bin/false" | %{_sbindir}/newusers +%{_bindir}/loginctl enable-linger pmm-server + +%post systemd +%systemd_post pmm-server.service +%{_bindir}/systemctl enable pmm-server >/dev/null 2>&1 || true + +%preun systemd +%systemd_preun pmm-server.service + +%postun systemd +%systemd_postun_with_restart pmm-server.service +if [ $1 == 0 ]; then + # This is a yum remove. + %{_bindir}/loginctl terminate-user pmm-server || true + getent passwd pmm-server >/dev/null && %{_sbindir}/userdel pmm-server + getent group pmm >/dev/null && %{_sbindir}/groupdel pmm +fi %files %license LICENSE @@ -59,8 +101,18 @@ rm -rf %{pmm_repo}-%{pmm_commit} %{_sysconfdir}/alertmanager.yml %{_datadir}/%{name} +%files systemd +%license LICENSE +%doc README.md CHANGELOG.md +%{_sysconfdir}/%{repo} +%config(noreplace) %{_sysconfdir}/%{repo}/pmm-server.env +%{_unitdir}/pmm-server.service %changelog + +* Tue May 31 2022 Denys Kondratenko - 2.29.0-2 +- PMM-7925 add systemd service with podman support + * Mon May 16 2022 Nikita Beletskii - 2.29.0-1 - PMM-10027 remove useless packages