Skip to content

Commit

Permalink
Merge pull request #55 from jancajthaml-openbank/bugfix/pure-enable-s…
Browse files Browse the repository at this point in the history
…ervices

pure enabling of service files with symlinks
  • Loading branch information
jancajthaml authored Jun 26, 2019
2 parents 8beb59f + b1456b9 commit 8f16ea3
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 135 deletions.
51 changes: 30 additions & 21 deletions packaging/debian_amd64/DEBIAN/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,43 @@

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}"
}

register_cron_job() {
ontime="30 14 * * * set -a; systemctl start cnb-rates-import"
crontab -l | grep -v 'cnb-rates-import' | crontab -
crontab -l | { cat; echo "${ontime}"; } | crontab -
}

case "$1" in

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

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

ontime="30 14 * * * set -a; systemctl start cnb-rates-import"
crontab -l | grep -v 'cnb-rates-import' | crontab -
crontab -l | { cat; echo "${ontime}"; } | crontab -
enable cnb-rates.path
enable cnb-rates.service
enable cnb-rates-rest.service
enable cnb-rates-import.service

if [ -d /run/systemd/system ] ; then
if [ ${SYSTEMD_AVAIL} ] ; then
(systemctl daemon-reload || :)
(systemctl start cnb-rates.service >/dev/null || :)
fi

register_cron_job

else
(>&2 echo "/etc/init/cnb-rates.conf file not found")
exit 1
Expand Down
52 changes: 28 additions & 24 deletions packaging/debian_amd64/DEBIAN/postrm
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,34 @@

set -e

delete_service_files() {
if [ -f "/lib/systemd/system/cnb-rates-rest.service" ] ; then
rm /lib/systemd/system/cnb-rates-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/cnb-rates-import.service" ] ; then
rm /lib/systemd/system/cnb-rates-import.service
fi
delete_service_files() {
delete /etc/systemd/cnb-rates.service.wants/cnb-rates-rest.service
delete /lib/systemd/system/cnb-rates-rest.service

if [ -f "/lib/systemd/system/cnb-rates-batch.service" ] ; then
rm /lib/systemd/system/cnb-rates-batch.service
fi
delete /etc/systemd/cnb-rates.service.wants/cnb-rates-import.service
delete /lib/systemd/system/cnb-rates-import.service

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

if [ -f "/lib/systemd/system/cnb-rates.path" ] ; then
rm /lib/systemd/system/cnb-rates.path
fi
delete /etc/systemd/multi-user.target.wants/cnb-rates.service
delete /lib/systemd/system/cnb-rates.service
}

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

unregister_cron_job() {
Expand All @@ -37,13 +39,12 @@ unregister_cron_job() {
case "$1" in

purge)
# userdel openbank || :

unregister_cron_job

delete_service_files
delete_displace_files

if [ -d /run/systemd/system ] ; then
if [ ${SYSTEMD_AVAIL} ] ; then
(systemctl daemon-reload || :)
(systemctl reset-failed || :)
fi
Expand All @@ -52,16 +53,19 @@ case "$1" in
remove)
unregister_cron_job

if [ -d /run/systemd/system ] ; then
if [ ${SYSTEMD_AVAIL} ] ; then
(systemctl -a -t service --no-legend | awk '$1 ~ /cnb-rates/ { 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 cnb-rates 2> /dev/null || :
fi
;;
Expand Down
51 changes: 30 additions & 21 deletions packaging/debian_arm64/DEBIAN/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,43 @@

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}"
}

register_cron_job() {
ontime="30 14 * * * set -a; systemctl start cnb-rates-import"
crontab -l | grep -v 'cnb-rates-import' | crontab -
crontab -l | { cat; echo "${ontime}"; } | crontab -
}

case "$1" in

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

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

ontime="30 14 * * * set -a; systemctl start cnb-rates-import"
crontab -l | grep -v 'cnb-rates-import' | crontab -
crontab -l | { cat; echo "${ontime}"; } | crontab -
enable cnb-rates.path
enable cnb-rates.service
enable cnb-rates-rest.service
enable cnb-rates-import.service

if [ -d /run/systemd/system ] ; then
if [ ${SYSTEMD_AVAIL} ] ; then
(systemctl daemon-reload || :)
(systemctl start cnb-rates.service >/dev/null || :)
fi

register_cron_job

else
(>&2 echo "/etc/init/cnb-rates.conf file not found")
exit 1
Expand Down
52 changes: 28 additions & 24 deletions packaging/debian_arm64/DEBIAN/postrm
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,34 @@

set -e

delete_service_files() {
if [ -f "/lib/systemd/system/cnb-rates-rest.service" ] ; then
rm /lib/systemd/system/cnb-rates-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/cnb-rates-import.service" ] ; then
rm /lib/systemd/system/cnb-rates-import.service
fi
delete_service_files() {
delete /etc/systemd/cnb-rates.service.wants/cnb-rates-rest.service
delete /lib/systemd/system/cnb-rates-rest.service

if [ -f "/lib/systemd/system/cnb-rates-batch.service" ] ; then
rm /lib/systemd/system/cnb-rates-batch.service
fi
delete /etc/systemd/cnb-rates.service.wants/cnb-rates-import.service
delete /lib/systemd/system/cnb-rates-import.service

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

if [ -f "/lib/systemd/system/cnb-rates.path" ] ; then
rm /lib/systemd/system/cnb-rates.path
fi
delete /etc/systemd/multi-user.target.wants/cnb-rates.service
delete /lib/systemd/system/cnb-rates.service
}

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

unregister_cron_job() {
Expand All @@ -37,13 +39,12 @@ unregister_cron_job() {
case "$1" in

purge)
# userdel openbank || :

unregister_cron_job

delete_service_files
delete_displace_files

if [ -d /run/systemd/system ] ; then
if [ ${SYSTEMD_AVAIL} ] ; then
(systemctl daemon-reload || :)
(systemctl reset-failed || :)
fi
Expand All @@ -52,16 +53,19 @@ case "$1" in
remove)
unregister_cron_job

if [ -d /run/systemd/system ] ; then
if [ ${SYSTEMD_AVAIL} ] ; then
(systemctl -a -t service --no-legend | awk '$1 ~ /cnb-rates/ { 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 cnb-rates 2> /dev/null || :
fi
;;
Expand Down
51 changes: 30 additions & 21 deletions packaging/debian_armhf/DEBIAN/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,43 @@

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}"
}

register_cron_job() {
ontime="30 14 * * * set -a; systemctl start cnb-rates-import"
crontab -l | grep -v 'cnb-rates-import' | crontab -
crontab -l | { cat; echo "${ontime}"; } | crontab -
}

case "$1" in

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

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

ontime="30 14 * * * set -a; systemctl start cnb-rates-import"
crontab -l | grep -v 'cnb-rates-import' | crontab -
crontab -l | { cat; echo "${ontime}"; } | crontab -
enable cnb-rates.path
enable cnb-rates.service
enable cnb-rates-rest.service
enable cnb-rates-import.service

if [ -d /run/systemd/system ] ; then
if [ ${SYSTEMD_AVAIL} ] ; then
(systemctl daemon-reload || :)
(systemctl start cnb-rates.service >/dev/null || :)
fi

register_cron_job

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

0 comments on commit 8f16ea3

Please sign in to comment.