Skip to content

Commit

Permalink
[PMM-13031]: Upgrades PMM 2 client with PMM 3 client. (#3182)
Browse files Browse the repository at this point in the history
  • Loading branch information
maqeel75 authored Sep 24, 2024
1 parent 574ff35 commit 1fe2a11
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 5 deletions.
2 changes: 2 additions & 0 deletions build/packages/deb/control
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Build-Depends: debhelper
Package: pmm-client
Architecture: any
Breaks: pmm-client
Conflicts: pmm2-client
Replaces: pmm2-client
Description: Percona Monitoring and Management Client
Percona Monitoring and Management (PMM) is an open-source platform for managing and monitoring MySQL and MongoDB
performance. It is developed by Percona in collaboration with experts in the field of managed database services,
Expand Down
27 changes: 22 additions & 5 deletions build/packages/deb/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,28 @@ fi

case "$1" in
configure)
chown -R pmm-agent:pmm-agent /usr/local/percona/pmm
if [ ! -f /usr/local/percona/pmm/config/pmm-agent.yaml ]; then
install -d -m 0755 /usr/local/percona/pmm/config
install -m 0660 -o pmm-agent -g pmm-agent /dev/null /usr/local/percona/pmm/config/pmm-agent.yaml
fi
chown -R pmm-agent:pmm-agent /usr/local/percona/pmm
if [ ! -f /usr/local/percona/pmm/config/pmm-agent.yaml ]; then
install -d -m 0755 /usr/local/percona/pmm/config
install -m 0660 -o pmm-agent -g pmm-agent /dev/null /usr/local/percona/pmm/config/pmm-agent.yaml
fi

# Backup the new pmm-agent.yaml if it exists
if [ -f /usr/local/percona/pmm2/config/pmm-agent.yaml.bak ]; then
echo "Backing up the new pmm-agent.yaml as pmm-agent.yaml.new..."
mv /usr/local/percona/pmm/config/pmm-agent.yaml /usr/local/percona/pmm/config/pmm-agent.yaml.new

echo "Restoring pmm-agent.yaml from backup..."
mv /usr/local/percona/pmm2/config/pmm-agent.yaml.bak /usr/local/percona/pmm/config/pmm-agent.yaml

# Clean up old directories if empty
if [ -d /usr/local/percona/pmm2/config ] && [ -z "$(ls -A /usr/local/percona/pmm2/config)" ]; then
rmdir /usr/local/percona/pmm2/config
fi
if [ -d /usr/local/percona/pmm2 ] && [ -z "$(ls -A /usr/local/percona/pmm2)" ]; then
rmdir /usr/local/percona/pmm2
fi
fi
;;

abort-upgrade|abort-remove|abort-deconfigure)
Expand Down
10 changes: 10 additions & 0 deletions build/packages/deb/postrm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ if [ "$1" = "purge" ]; then
if [ -f /usr/local/percona/pmm/config/pmm-agent.yaml ]; then
rm -f /usr/local/percona/pmm/config/pmm-agent.yaml
fi
if [ -f /usr/local/percona/pmm/config/pmm-agent.yaml.new ]; then
rm -f /usr/local/percona/pmm/config/pmm-agent.yaml.new
fi

if [ -d /usr/local/percona/pmm/config ] && [ -z "$(ls -A /usr/local/percona/pmm/config)" ]; then
rmdir /usr/local/percona/pmm/config
fi
if [ -d /usr/local/percona/pmm ] && [ -z "$(ls -A /usr/local/percona/pmm)" ]; then
rmdir /usr/local/percona/pmm
fi
fi

#DEBHELPER#
Expand Down
5 changes: 5 additions & 0 deletions build/packages/deb/preinst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ if ! getent passwd pmm-agent >/dev/null 2>&1; then
adduser --system --home /usr/local/percona --group pmm-agent
fi

if [ -f /usr/local/percona/pmm2/config/pmm-agent.yaml ]; then
echo "Backing up pmm-agent.yaml before removing pmm2-client..."
mv /usr/local/percona/pmm2/config/pmm-agent.yaml /usr/local/percona/pmm2/config/pmm-agent.yaml.bak
fi

#DEBHELPER#

exit 0
23 changes: 23 additions & 0 deletions build/packages/rpm/client/pmm-client.spec
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Requires(postun): systemd

AutoReq: no
Conflicts: pmm-client
Obsoletes: pmm2-client < 3.0.0

%description
Percona Monitoring and Management (PMM) is an open-source platform for managing and monitoring MySQL and MongoDB
Expand All @@ -35,6 +36,24 @@ as possible.
%prep
%setup -q

%pretrans
if [ -f /usr/local/percona/pmm2/config/pmm-agent.yaml ]; then
cp -a /usr/local/percona/pmm2/config/pmm-agent.yaml /usr/local/percona/pmm2/config/pmm-agent.yaml.bak
fi

%posttrans
if [ -f /usr/local/percona/pmm2/config/pmm-agent.yaml.bak ]; then
mv /usr/local/percona/pmm/config/pmm-agent.yaml /usr/local/percona/pmm/config/pmm-agent.yaml.new
mv /usr/local/percona/pmm2/config/pmm-agent.yaml.bak /usr/local/percona/pmm/config/pmm-agent.yaml

if [ -d /usr/local/percona/pmm2/config ] && [ ! "$(ls -A /usr/local/percona/pmm2/config)" ]; then
rmdir /usr/local/percona/pmm2/config
fi

if [ -d /usr/local/percona/pmm2 ] && [ ! "$(ls -A /usr/local/percona/pmm2)" ]; then
rmdir /usr/local/percona/pmm2
fi
fi

%build

Expand Down Expand Up @@ -132,6 +151,10 @@ fi
%preun
%systemd_preun pmm-agent.service

if [ -f /usr/local/percona/pmm/config/pmm-agent.yaml.new ]; then
rm -f /usr/local/percona/pmm/config/pmm-agent.yaml.new
fi

%postun
case "$1" in
0) # This is a yum remove.
Expand Down

0 comments on commit 1fe2a11

Please sign in to comment.