2018-03-13 10:46:40 +01:00
#!/bin/sh
2011-08-23 07:40:22 +02:00
2022-09-14 10:48:19 +02:00
# Abort if any command returns an error value
2011-08-23 07:40:22 +02:00
set -e
2022-09-14 10:48:19 +02:00
# This script is called as the last step of the installation of the package.
# All the package's files are in place, dpkg has already done its automatic
# conffile handling, and all the packages we depend of are already fully
# installed and configured.
2011-08-23 07:40:22 +02:00
2021-06-23 11:00:25 +02:00
set_lvm_conf() {
2023-12-22 10:58:06 +01:00
local FORCE="$1"
2021-06-23 11:00:25 +02:00
LVM_CONF_MARKER="# added by pve-manager to avoid scanning"
# keep user changes afterwards provided marker is still there..
2023-12-22 10:58:06 +01:00
if grep -qLF "$LVM_CONF_MARKER" /etc/lvm/lvm.conf && test -z "$FORCE"; then
2022-09-14 10:48:53 +02:00
return 0 # only do these changes once
fi
2022-09-14 10:48:19 +02:00
2022-09-14 10:48:53 +02:00
export LVM_SUPPRESS_FD_WARNINGS=1
2023-12-22 10:58:06 +01:00
OLD_VALUE="$(lvmconfig --typeconfig diff devices/global_filter || true)"
NEW_VALUE='global_filter=["r|/dev/zd.*|","r|/dev/rbd.*|"]'
# update global_filter if:
# it is empty and there is no marker OR exactly the one we set before 8.1.4
if (! grep -qF "$LVM_CONF_MARKER" /etc/lvm/lvm.conf && test -z "$OLD_VALUE")\
2024-01-10 10:35:41 +01:00
|| (echo "$OLD_VALUE" | grep -qF '="r|/dev/zd.*|"');
2023-12-22 10:58:06 +01:00
then
2022-09-14 10:48:53 +02:00
SET_FILTER=1
BACKUP=1
2023-12-22 10:58:06 +01:00
# print warning if global_filter is set but not our old/new default
elif test -n "$OLD_VALUE"\
2024-01-10 10:35:41 +01:00
&& ! echo "$OLD_VALUE" | grep -qF '="r|/dev/zd.*|"'\
&& ! echo "$OLD_VALUE" | grep -qF "$NEW_VALUE";
2023-12-22 10:58:06 +01:00
then
2024-01-10 10:35:41 +01:00
echo "non-default 'global_filter' value '$OLD_VALUE' in /etc/lvm/lvm.conf, not setting '$NEW_VALUE' automatically"
echo "consider adapting your 'global_filter' manually."
2022-09-14 10:48:53 +02:00
fi
# should be the default since bullseye
if lvmconfig --typeconfig full devices/scan_lvs | grep -qv 'scan_lvs=0'; then
SET_SCAN_LVS=1
BACKUP=1
fi
if test -n "$BACKUP"; then
echo "Backing up lvm.conf before setting pve-manager specific settings.."
cp -vb /etc/lvm/lvm.conf /etc/lvm/lvm.conf.bak
fi
if test -n "$SET_FILTER"; then
2023-12-22 10:58:06 +01:00
echo "Setting 'global_filter' in /etc/lvm/lvm.conf to prevent zvols and rbds from being scanned:"
2022-09-14 10:48:53 +02:00
echo "$OLD_VALUE => $NEW_VALUE"
2023-12-22 10:58:06 +01:00
if test -n "$OLD_VALUE"; then
sed -i -e "s/$LVM_CONF_MARKER ZFS zvols/$LVM_CONF_MARKER ZFS zvols and Ceph rbds/" /etc/lvm/lvm.conf
sed -i -e "s!^\([[:space:]]*\)\(global_filter[[:space:]]*=.*\)\$!\1# \2\n\1$NEW_VALUE!" /etc/lvm/lvm.conf
else
cat >> /etc/lvm/lvm.conf <<EOF
2021-06-23 11:00:25 +02:00
devices {
2023-12-22 10:58:06 +01:00
$LVM_CONF_MARKER ZFS zvols and Ceph rbds
2022-09-14 10:48:19 +02:00
$NEW_VALUE
2023-12-22 10:58:06 +01:00
}
2021-06-23 11:00:25 +02:00
EOF
2023-12-22 10:58:06 +01:00
fi
2022-09-14 10:48:53 +02:00
fi
if test -n "$SET_SCAN_LVS"; then
echo "Adding scan_lvs=0 setting to /etc/lvm/lvm.conf to prevent LVs from being scanned."
# comment out existing setting
sed -i -e 's/^\([[:space:]]*scan_lvs[[:space:]]*=\)/#\1/' /etc/lvm/lvm.conf
# add new section with our setting
cat >> /etc/lvm/lvm.conf <<EOF
2021-06-23 11:00:25 +02:00
devices {
2022-09-14 10:48:19 +02:00
$LVM_CONF_MARKER LVM volumes
scan_lvs=0
}
2021-06-23 11:00:25 +02:00
EOF
fi
2023-12-22 10:58:06 +01:00
if ! lvmconfig --validate; then
2024-01-10 10:35:41 +01:00
echo "Invalid LVM config detected - restoring from /etc/lvm/lvm.conf.bak"
mv /etc/lvm/lvm.conf.bak /etc/lvm/lvm.conf
2023-12-22 10:58:06 +01:00
fi
2021-06-23 11:00:25 +02:00
}
2024-04-02 16:55:21 +02:00
update_ceph_conf() {
2024-04-02 16:55:22 +02:00
UNIT='ceph-crash.service'
# Don't fail in case user has "exotic" configuration where RADOS
# isn't available on all nodes for some reason
/usr/share/pve-manager/helpers/pve-init-ceph-crash || true
if systemctl -q is-enabled "$UNIT" 2> /dev/null; then
deb-systemd-invoke restart "$UNIT" || true
fi
2024-04-02 16:55:21 +02:00
}
2022-09-14 10:05:54 +02:00
migrate_apt_auth_conf() {
output=""
removed=""
match=0
while read -r l; do
2022-09-14 10:48:19 +02:00
if echo "$l" | grep -q "^machine enterprise.proxmox.com/debian/pve"; then
match=1
elif echo "$l" | grep -q "machine"; then
match=0
fi
if test "$match" = "1"; then
removed="$removed\n$l"
else
output="$output\n$l"
fi
2022-09-14 10:05:54 +02:00
done < /etc/apt/auth.conf
if test -n "$removed"; then
2022-09-14 10:48:19 +02:00
if test ! -e /etc/apt/auth.conf.d/pve.conf; then
echo "Migrating APT auth config for enterprise.proxmox.com to /etc/apt/auth.conf.d/pve.conf .."
echo "$removed" > /etc/apt/auth.conf.d/pve.conf
else
echo "Removing stale APT auth config from /etc/apt/auth.conf"
fi
echo "$output" > /etc/apt/auth.conf
2022-09-14 10:05:54 +02:00
fi
}
2011-08-23 07:40:22 +02:00
case "$1" in
triggered)
# We don't print a status message here, as dpkg already said
# "Processing triggers for ...".
2011-10-04 07:02:02 +02:00
# test if /etc/pve is mounted; else simple exit to avoid
# error during updates
test -f /etc/pve/local/pve-ssl.pem || exit 0;
2015-02-28 12:42:20 +01:00
test -e /proxmox_install_mode && exit 0;
2015-06-01 13:03:08 +02:00
2020-05-03 18:50:58 +02:00
# the ExecStartPre doesn't triggers on service reload, so just in case
2021-10-04 10:38:56 +02:00
pvecm updatecerts --silent || true
2020-05-03 18:50:58 +02:00
2024-04-11 12:10:48 +02:00
deb-systemd-invoke reload-or-try-restart pvedaemon.service || true
deb-systemd-invoke reload-or-try-restart pvestatd.service || true
deb-systemd-invoke reload-or-try-restart pveproxy.service || true
deb-systemd-invoke reload-or-try-restart spiceproxy.service || true
deb-systemd-invoke reload-or-try-restart pvescheduler.service || true
2011-08-23 07:40:22 +02:00
exit 0;;
configure)
# Configure this package. If the package must prompt the user for
# information, do it here.
mkdir /etc/pve 2>/dev/null || true
2012-02-21 12:15:10 +01:00
if test ! -e /var/lib/pve-manager/apl-info/download.proxmox.com; then
2022-09-14 10:48:19 +02:00
mkdir -p /var/lib/pve-manager/apl-info
cp /usr/share/doc/pve-manager/aplinfo.dat /var/lib/pve-manager/apl-info/download.proxmox.com
pveam update || true
2012-02-21 12:15:10 +01:00
fi
2022-10-21 15:02:50 +02:00
# Always try to clean old entry, even when proxmox-mail-forward entry is already present.
# This ensures it will still be cleaned after an upgrade following a downgrade.
if test -f /root/.forward; then
sed -i '\!|/usr/bin/pvemailforward!d' /root/.forward
fi
if ! test -f /root/.forward || ! grep -q '|/usr/bin/proxmox-mail-forward' /root/.forward; then
echo '|/usr/bin/proxmox-mail-forward' >>/root/.forward
2012-01-18 09:45:54 +01:00
fi
2013-03-26 07:16:26 +01:00
2015-02-28 12:42:20 +01:00
systemctl --system daemon-reload >/dev/null || true
# same as dh_systemd_enable (code copied)
replace systemd timer with pvescheduler daemon
The whole thing is already prepared for this, the systemd timer was
just a fixed periodic timer with a frequency of one minute. And we
just introduced it as the assumption was made that less memory usage
would be generated with this approach, AFAIK.
But logging 4+ lines just about that the timer was started, even if
it does nothing, and that 24/7 is not to cheap and a bit annoying.
So in a first step add a simple daemon, which forks of a child for
running jobs once a minute.
This could be made still a bit more intelligent, i.e., look if we
have jobs tor run before forking - as forking is not the cheapest
syscall. Further, we could adapt the sleep interval to the next time
we actually need to run a job (and sending a SIGUSR to the daemon if
a job interval changes such, that this interval got narrower)
We try to sync running on minute-change boundaries at start, this
emulates systemd.timer behaviour, we had until now. Also user can
configure jobs on minute precision, so they probably expect that
those also start really close to a minute change event.
Could be adapted to resync during running, to factor in time drift.
But, as long as enough cpu cycles are available we run in correct
monotonic intervalls, so this isn't a must, IMO.
Another improvement could be locking a bit more fine grained, i.e.
not on a per-all-local-job-runs basis, but per-job (per-guest?)
basis, which would improve temporary starvement of small
high-periodic jobs through big, less peridoci jobs.
We argued that it's the user fault if such situations arise, but they
can evolve over time without noticing, especially in compolexer
setups.
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2021-11-08 14:07:53 +01:00
UNITS="pvedaemon.service pveproxy.service spiceproxy.service pvestatd.service pvebanner.service pvescheduler.service pve-daily-update.timer"
2018-03-13 10:46:37 +01:00
NO_RESTART_UNITS="pvenetcommit.service pve-guests.service"
2017-06-02 11:21:46 +02:00
2018-03-13 10:46:37 +01:00
for unit in ${UNITS} ${NO_RESTART_UNITS}; do
2022-09-14 10:48:19 +02:00
deb-systemd-helper unmask "$unit" >/dev/null || true
# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet was-enabled "$unit"; then
# Enables the unit on first installation, creates new
# symlinks on upgrades if the unit file has changed.
deb-systemd-helper enable "$unit" >/dev/null || true
else
# Update the statefile to add new symlinks (if any), which need to be
# cleaned up on purge. Also remove old symlinks.
deb-systemd-helper update-state "$unit" >/dev/null || true
fi
2015-02-28 12:42:20 +01:00
done
2021-06-23 22:25:09 +02:00
# FIXME: remove after beta is over and add hunk to actively remove the repo
BETA_SOURCES="/etc/apt/sources.list.d/pvetest-for-beta.list"
2023-06-21 17:06:31 +02:00
if test -f "$BETA_SOURCES" && dpkg --compare-versions "$2" 'lt' '8.0.2' && dpkg --compare-versions "$2" 'gt' '8.0~'; then
2023-06-19 11:13:34 +02:00
echo "Removing the during beta added pvetest repository file again"
rm -v "$BETA_SOURCES" || true
2021-06-23 22:25:09 +02:00
fi
2023-12-22 10:58:06 +01:00
if test ! -e /proxmox_install_mode && test -n "$2" && dpkg --compare-versions "$2" 'lt' '8.1.4~'; then
if test -e /etc/lvm/lvm.conf ; then
set_lvm_conf 1
fi
fi
2021-06-23 11:00:25 +02:00
set_lvm_conf
2024-04-11 10:55:35 +02:00
if test -n "$2" && dpkg --compare-versions "$2" 'lt' '8.1.11'; then
2024-04-02 16:55:21 +02:00
update_ceph_conf
fi
2015-02-28 12:42:20 +01:00
if test ! -e /proxmox_install_mode; then
2022-09-14 10:48:19 +02:00
# modeled after code generated by dh_start
for unit in ${UNITS}; do
if test -n "$2"; then
dh_action="reload-or-restart";
else
dh_action="start"
fi
if systemctl -q is-enabled "$unit"; then
2024-04-11 12:10:48 +02:00
deb-systemd-invoke $dh_action "$unit" || true
2022-09-14 10:48:19 +02:00
fi
done
2015-02-28 12:42:20 +01:00
fi
2022-09-14 10:05:54 +02:00
2023-05-29 15:41:35 +02:00
if test ! -e /proxmox_install_mode && test -n "$2" && dpkg --compare-versions "$2" 'lt' '7.2-11~'; then
2022-09-14 10:48:19 +02:00
if test -e /etc/apt/auth.conf ; then
migrate_apt_auth_conf
fi
2022-09-14 10:05:54 +02:00
fi
2018-03-12 14:14:01 +01:00
;;
2011-08-23 07:40:22 +02:00
2018-03-12 14:14:00 +01:00
abort-upgrade|abort-remove|abort-deconfigure)
2011-08-23 07:40:22 +02:00
;;
*) echo "$0: didn't understand being called with \`$1'" 1>&2
exit 0;;
esac
exit 0