Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deb package post install #3720

Merged
merged 3 commits into from
Dec 14, 2022
Merged

Conversation

bubu11e
Copy link
Collaborator

@bubu11e bubu11e commented Dec 13, 2022

What this PR does

This pull request fix two things with the post-install of the Debian package:

  • The environment path was wrong in one place
  • The user creation was not working properly

Which issue(s) this PR fixes or relates to

Fixes #3471

More details

Here is the complete old post-install script (after fpm process):

#!/bin/sh


after_upgrade() {
    :

systemctl --system daemon-reload >/dev/null || true
debsystemctl=$(command -v deb-systemd-invoke || echo systemctl)
if ! systemctl is-enabled mimir >/dev/null 
then
  : # Ensure this if-clause is not empty. If it were empty, and we had an 'else', then it is an error in shell syntax
else
    $debsystemctl restart mimir >/dev/null || true
fi
}

after_install() {
    :
#!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-only
# Provenance-includes-location: https://github.com/cortexproject/cortex/blob/master/packaging/deb/control/postinst
# Provenance-includes-license: Apache-2.0
# Provenance-includes-copyright: The Cortex Authors.

set -e

# shellcheck disable=1091
[ -f /etc/sysconfig/mimir ] && . /etc/default/mimir

case "$1" in
  configure)
    [ -z "$MIMIR_USER" ] && MIMIR_USER="mimir"
    [ -z "$MIMIR_GROUP" ] && MIMIR_GROUP="mimir"
    if ! getent group "$MIMIR_GROUP" >/dev/null 2>&1; then
      groupadd -r "$MIMIR_GROUP"
    fi
    if ! getent passwd "$MIMIR_USER" >/dev/null 2>&1; then
      useradd -m -r -g mimir -d /var/lib/mimir -s /sbin/nologin -c "mimir user" mimir
    fi

    chmod 640 /etc/mimir/config.example.yaml
    chown root:$MIMIR_GROUP /etc/mimir/config.example.yaml

    if [ -z ${2+x} ] && [ "$RESTART_ON_UPGRADE" = "true" ]; then
      if command -v systemctl 2>/dev/null; then
        systemctl daemon-reload
      fi
    fi
    ;;
esac


systemctl --system daemon-reload >/dev/null || true
debsystemctl=$(command -v deb-systemd-invoke || echo systemctl)
}

if [ "${1}" = "configure" -a -z "${2}" ] || \
   [ "${1}" = "abort-remove" ]
then
    # "after install" here
    # "abort-remove" happens when the pre-removal script failed.
    #   In that case, this script, which should be idemptoent, is run
    #   to ensure a clean roll-back of the removal.
    after_install
elif [ "${1}" = "configure" -a -n "${2}" ]
then
    upgradeFromVersion="${2}"
    # "after upgrade" here
    # NOTE: This slot is also used when deb packages are removed,
    # but their config files aren't, but a newer version of the
    # package is installed later, called "Config-Files" state.
    # basically, that still looks a _lot_ like an upgrade to me.
    after_upgrade "${2}"
elif echo "${1}" | grep -E -q "(abort|fail)"
then
    echo "Failed to install before the post-installation script was run." >&2
    exit 1
fi

Call to function after_install is made without any argument, therefore case statement can't work.

Here is the result of the dpkg -icommand:

$ sudo dpkg -i mimir-2.4.0_amd64.deb
Selecting previously unselected package mimir.
(Reading database ... 21185 files and directories currently installed.)
Preparing to unpack mimir-2.4.0_amd64.deb ...
Unpacking mimir (2.4.0) ...
Setting up mimir (2.4.0) ...
/usr/bin/systemctl

User is now well created :

$ cat /etc/passwd
***
mimir:x:997:997:mimir user:/var/lib/mimir:/sbin/nologin

You will find a package attached to this PR to test yourself.
debian_packages.tar.gz

Signed-off-by: julien.girard <julien.girard@ovhcloud.com>
@bubu11e bubu11e requested a review from a team as a code owner December 13, 2022 15:51
@CLAassistant
Copy link

CLAassistant commented Dec 13, 2022

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@56quarters 56quarters left a comment

Choose a reason for hiding this comment

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

LGTM after the lint is fixed. Thanks!

CHANGELOG.md Outdated Show resolved Hide resolved
Function after_install isn't called with arguments and therefore
case can't work here. FPM already take care of matching this
argument at postinstall call.

See: https://github.com/jordansissel/fpm/blob/main/templates/deb/postinst_upgrade.sh.erb#L63

Signed-off-by: julien.girard <julien.girard@ovhcloud.com>
@56quarters 56quarters merged commit a758c4e into grafana:main Dec 14, 2022
masonmei pushed a commit to udmire/mimir that referenced this pull request Dec 16, 2022
* Fix environment file path in post install for debian package

Signed-off-by: julien.girard <julien.girard@ovhcloud.com>

* Fix mimir user creation in post install for debian package

Function after_install isn't called with arguments and therefore
case can't work here. FPM already take care of matching this
argument at postinstall call.

See: https://github.com/jordansissel/fpm/blob/main/templates/deb/postinst_upgrade.sh.erb#L63

Signed-off-by: julien.girard <julien.girard@ovhcloud.com>

Signed-off-by: julien.girard <julien.girard@ovhcloud.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mimir from grafana ubuntu / debian repo service failed to start
3 participants