Browse Source

Use systemd helpers to honor system wide preferences on service enable/start

Also fix services being started after upgrade even if they were disabled but config existed
pull/60/head
emanuele-f 6 years ago
parent
commit
a96237f83d
  1. 20
      packages/debian/debian/postinst
  2. 10
      packages/debian/debian/prerm
  3. 26
      packages/rpm/n2n.spec.in

20
packages/debian/debian/postinst

@ -27,17 +27,21 @@ systemctl daemon-reload
systemctl reset-failed
# Enable edge
if [ -f /etc/n2n/edge.conf ]; then
echo "Enabling n2n edge..."
systemctl enable edge
systemctl restart edge
if systemctl -q is-active edge; then
# only restart edge if it's already running
echo "Restarting n2n edge..."
deb-systemd-invoke restart edge
fi
# Restart specific services if already running
deb-systemd-invoke enable 'edge@*.service' 'edge-ntopng@*.service'
deb-systemd-invoke restart 'edge@*.service' 'edge-ntopng@*.service'
# Enable supernode
if [ -f /etc/n2n/supernode.conf ]; then
echo "Enabling n2n supernode..."
systemctl enable supernode
systemctl restart supernode
if systemctl -q is-active supernode; then
# only restart supernode if it's already running
echo "Restarting n2n supernode..."
deb-systemd-invoke restart supernode
fi
exit 0

10
packages/debian/debian/prerm

@ -7,12 +7,14 @@ if [ -f /.dockerenv ]; then exit 0; fi
. /usr/share/debconf/confmodule
case "$1" in
upgrade)
;;
*)
systemctl stop edge
systemctl disable edge
systemctl stop supernode
systemctl disable supernode
deb-systemd-invoke stop edge.service 'edge@*.service' 'edge-ntopng@*.service'
deb-systemd-invoke disable edge.service 'edge@*.service' 'edge-ntopng@*.service'
deb-systemd-invoke stop supernode.service
deb-systemd-invoke disable supernode.service
systemctl daemon-reload
systemctl reset-failed
;;

26
packages/rpm/n2n.spec.in

@ -70,29 +70,19 @@ rm -fr $RPM_BUILD_ROOT
%pre
%post
if [ ! -f /.dockerenv ]; then
/bin/systemctl daemon-reload
if [ -f /etc/n2n/edge.conf ]; then
/bin/systemctl enable edge.service
/bin/systemctl restart edge.service
fi
if [ -f /etc/n2n/supernode.conf ]; then
/bin/systemctl enable supernode.service
/bin/systemctl restart supernode.service
fi
/bin/systemctl daemon-reload
# NOTE: do not enable any services during first installation
fi
%preun
if [ ! -f /.dockerenv ]; then
if [ -f /etc/n2n/edge.conf ]; then
/bin/systemctl disable edge.service
/bin/systemctl stop edge.service
# possibly remove the installed services
%systemd_preun supernode.service edge.service 'edge-ntopng@*.service' 'edge@*.service'
fi
if [ -f /etc/n2n/supernode.conf ]; then
/bin/systemctl disable supernode.service
/bin/systemctl stop supernode.service
fi
%postun
if [ ! -f /.dockerenv ]; then
# possibly restart the running services
%systemd_postun_with_restart supernode.service edge.service 'edge-ntopng@*.service' 'edge@*.service'
fi

Loading…
Cancel
Save