Skip to content

Commit

Permalink
pure enabling of service files with symlinks (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
jancajthaml authored Jun 25, 2019
1 parent 77f689b commit 2ff2978
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 106 deletions.
2 changes: 1 addition & 1 deletion packaging/debian_amd64/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: vault
Version: 1.2.7+account-format
Version: 1.2.8+pure-enable-services
Section: misc
Priority: extra
Architecture: amd64
Expand Down
36 changes: 22 additions & 14 deletions packaging/debian_amd64/DEBIAN/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,34 @@

set -e

if [ "$(ps -o comm -p 1 --no-headers | tr -d ' ')" = "systemd" ] ; then
SYSTEMD_AVAIL=true
else
SYSTEMD_AVAIL=false
fi

enable() {
wanted_by=$(cat /lib/systemd/system/${1} | sed -n -e 's/^.*WantedBy=//p')
mkdir -p /etc/systemd/system/${wanted_by}.wants
ln -s \
"/lib/systemd/system/${1}" \
"/etc/systemd/system/${wanted_by}.wants/${1}"
}

case "$1" in

configure)
if [ -f "/etc/init/vault.conf" ] ; then
if [ -d /run/systemd/system ] ; then
systemctl unmask \
vault.path \
vault-unit.service \
vault-rest.service \
vault.service \
>/dev/null

systemctl enable \
vault.path \
vault-rest.service \
vault.service \
>/dev/null
if [ -f /etc/init/vault.conf ] ; then

enable vault.path
enable vault.service
enable vault-rest.service

if [ ${SYSTEMD_AVAIL} ] ; then
(systemctl daemon-reload || :)
(systemctl start vault.service >/dev/null || :)
fi

else
(>&2 echo "/etc/init/vault.conf file not found")
exit 1
Expand Down
49 changes: 28 additions & 21 deletions packaging/debian_amd64/DEBIAN/postrm
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,62 @@

set -e

delete_service_files() {
if [ -f "/lib/systemd/system/vault-rest.service" ] ; then
rm /lib/systemd/system/vault-rest.service
if [ "$(ps -o comm -p 1 --no-headers | tr -d ' ')" = "systemd" ] ; then
SYSTEMD_AVAIL=true
else
SYSTEMD_AVAIL=false
fi

delete() {
if [ -f "${1}" ] ; then
rm "${1}"
fi
}

if [ -f "/lib/systemd/system/vault-unit@.service" ] ; then
rm /lib/systemd/system/vault-unit@.service
fi
delete_service_files() {
delete /etc/systemd/vault.service.wants/vault-rest.service
delete /lib/systemd/system/vault-rest.service

if [ -f "/lib/systemd/system/vault.service" ] ; then
rm /lib/systemd/system/vault.service
fi
delete /etc/systemd/vault.service.wants/vault-unit@.service
delete /lib/systemd/system/vault-unit@.service

if [ -f "/lib/systemd/system/vault.path" ] ; then
rm /lib/systemd/system/vault.path
fi
delete /etc/systemd/vault.service.wants/vault.path
delete /lib/systemd/system/vault.path

delete /etc/systemd/multi-user.target.wants/vault.service
delete /lib/systemd/system/vault.service
}

delete_displace_files() {
if [ -f "/etc/init/vault.conf" ] ; then
rm /etc/init/vault.conf
fi
delete /etc/init/vault.conf
}

case "$1" in

purge)
# userdel openbank || :

delete_service_files
delete_displace_files

if [ -d /run/systemd/system ] ; then
if [ ${SYSTEMD_AVAIL} ] ; then
(systemctl daemon-reload || :)
(systemctl reset-failed || :)
fi
;;

remove)
if [ -d /run/systemd/system ] ; then
if [ ${SYSTEMD_AVAIL} ] ; then
(systemctl -a -t service --no-legend | awk '$1 ~ /vault/ { print $1 }' | xargs -I {} systemctl stop {} 2> /dev/null || :)
(systemctl daemon-reload || :)
fi

delete_displace_files

if [ ${SYSTEMD_AVAIL} ] ; then
(systemctl daemon-reload || :)
fi
;;

upgrade|deconfigure)
if [ -d /run/systemd/system ] ; then
if [ ${SYSTEMD_AVAIL} ] ; then
systemctl stop vault 2> /dev/null || :
fi
;;
Expand Down
36 changes: 22 additions & 14 deletions packaging/debian_arm64/DEBIAN/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,34 @@

set -e

if [ "$(ps -o comm -p 1 --no-headers | tr -d ' ')" = "systemd" ] ; then
SYSTEMD_AVAIL=true
else
SYSTEMD_AVAIL=false
fi

enable() {
wanted_by=$(cat /lib/systemd/system/${1} | sed -n -e 's/^.*WantedBy=//p')
mkdir -p /etc/systemd/system/${wanted_by}.wants
ln -s \
"/lib/systemd/system/${1}" \
"/etc/systemd/system/${wanted_by}.wants/${1}"
}

case "$1" in

configure)
if [ -f "/etc/init/vault.conf" ] ; then
if [ -d /run/systemd/system ] ; then
systemctl unmask \
vault.path \
vault-unit.service \
vault-rest.service \
vault.service \
>/dev/null

systemctl enable \
vault.path \
vault-rest.service \
vault.service \
>/dev/null
if [ -f /etc/init/vault.conf ] ; then

enable vault.path
enable vault.service
enable vault-rest.service

if [ ${SYSTEMD_AVAIL} ] ; then
(systemctl daemon-reload || :)
(systemctl start vault.service >/dev/null || :)
fi

else
(>&2 echo "/etc/init/vault.conf file not found")
exit 1
Expand Down
49 changes: 28 additions & 21 deletions packaging/debian_arm64/DEBIAN/postrm
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,62 @@

set -e

delete_service_files() {
if [ -f "/lib/systemd/system/vault-rest.service" ] ; then
rm /lib/systemd/system/vault-rest.service
if [ "$(ps -o comm -p 1 --no-headers | tr -d ' ')" = "systemd" ] ; then
SYSTEMD_AVAIL=true
else
SYSTEMD_AVAIL=false
fi

delete() {
if [ -f "${1}" ] ; then
rm "${1}"
fi
}

if [ -f "/lib/systemd/system/vault-unit@.service" ] ; then
rm /lib/systemd/system/vault-unit@.service
fi
delete_service_files() {
delete /etc/systemd/vault.service.wants/vault-rest.service
delete /lib/systemd/system/vault-rest.service

if [ -f "/lib/systemd/system/vault.service" ] ; then
rm /lib/systemd/system/vault.service
fi
delete /etc/systemd/vault.service.wants/vault-unit@.service
delete /lib/systemd/system/vault-unit@.service

if [ -f "/lib/systemd/system/vault.path" ] ; then
rm /lib/systemd/system/vault.path
fi
delete /etc/systemd/vault.service.wants/vault.path
delete /lib/systemd/system/vault.path

delete /etc/systemd/multi-user.target.wants/vault.service
delete /lib/systemd/system/vault.service
}

delete_displace_files() {
if [ -f "/etc/init/vault.conf" ] ; then
rm /etc/init/vault.conf
fi
delete /etc/init/vault.conf
}

case "$1" in

purge)
# userdel openbank || :

delete_service_files
delete_displace_files

if [ -d /run/systemd/system ] ; then
if [ ${SYSTEMD_AVAIL} ] ; then
(systemctl daemon-reload || :)
(systemctl reset-failed || :)
fi
;;

remove)
if [ -d /run/systemd/system ] ; then
if [ ${SYSTEMD_AVAIL} ] ; then
(systemctl -a -t service --no-legend | awk '$1 ~ /vault/ { print $1 }' | xargs -I {} systemctl stop {} 2> /dev/null || :)
(systemctl daemon-reload || :)
fi

delete_displace_files

if [ ${SYSTEMD_AVAIL} ] ; then
(systemctl daemon-reload || :)
fi
;;

upgrade|deconfigure)
if [ -d /run/systemd/system ] ; then
if [ ${SYSTEMD_AVAIL} ] ; then
systemctl stop vault 2> /dev/null || :
fi
;;
Expand Down
36 changes: 22 additions & 14 deletions packaging/debian_armhf/DEBIAN/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,34 @@

set -e

if [ "$(ps -o comm -p 1 --no-headers | tr -d ' ')" = "systemd" ] ; then
SYSTEMD_AVAIL=true
else
SYSTEMD_AVAIL=false
fi

enable() {
wanted_by=$(cat /lib/systemd/system/${1} | sed -n -e 's/^.*WantedBy=//p')
mkdir -p /etc/systemd/system/${wanted_by}.wants
ln -s \
"/lib/systemd/system/${1}" \
"/etc/systemd/system/${wanted_by}.wants/${1}"
}

case "$1" in

configure)
if [ -f "/etc/init/vault.conf" ] ; then
if [ -d /run/systemd/system ] ; then
systemctl unmask \
vault.path \
vault-unit.service \
vault-rest.service \
vault.service \
>/dev/null

systemctl enable \
vault.path \
vault-rest.service \
vault.service \
>/dev/null
if [ -f /etc/init/vault.conf ] ; then

enable vault.path
enable vault.service
enable vault-rest.service

if [ ${SYSTEMD_AVAIL} ] ; then
(systemctl daemon-reload || :)
(systemctl start vault.service >/dev/null || :)
fi

else
(>&2 echo "/etc/init/vault.conf file not found")
exit 1
Expand Down
Loading

0 comments on commit 2ff2978

Please sign in to comment.