Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

PMM-7925: Add SystemD service with podman to run PMM #355

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions pmm-server-user.service
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions pmm-server.env
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we split environment variables between this file and service?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

service has environment for systemd/podman and env file is passed to pmm.

It is not split, it just another file to pass to env to pmm

31 changes: 31 additions & 0 deletions pmm-server.service
Original file line number Diff line number Diff line change
@@ -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
68 changes: 60 additions & 8 deletions rhel/SPECS/pmm-server.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand All @@ -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
Expand All @@ -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 <denys.kondratenko@percona.com> - 2.29.0-2
- PMM-7925 add systemd service with podman support

* Mon May 16 2022 Nikita Beletskii <nikita.beletskii@percona.com> - 2.29.0-1
- PMM-10027 remove useless packages

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we use this spec? We use this spec for internal pmm-server package (it contains some js files) and I'm not sure that we need systemd service in container :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was easier for PoC to use existing spec. And actually it fits it well in term that is a part of pmm-server. We don't need it in container for sure, but probably after build we need to sync it into some repo that available for everyone.

Expand Down