xbps-base-files: revamp the openrc-service trigger.

It has been modified to support restarting services while upgrading
packages, and simplified as well. Bump to 0.22.

--HG--
extra : convert_revision : 21b5aeaed7b76594c43f2e721c06d4e13d5f5f04
This commit is contained in:
Juan RP 2009-10-02 17:29:17 +02:00
parent 6b183bdf3b
commit 3463fbef0a
2 changed files with 42 additions and 21 deletions

View file

@ -1,6 +1,6 @@
# Template file for 'xbps-base-files' # Template file for 'xbps-base-files'
pkgname=xbps-base-files pkgname=xbps-base-files
version=0.21 version=0.22
build_style=custom-install build_style=custom-install
short_desc="xbps base system files" short_desc="xbps base system files"
maintainer="Juan RP <xtraeme@gmail.com>" maintainer="Juan RP <xtraeme@gmail.com>"

View file

@ -3,13 +3,22 @@
# Registers or unregisters OpenRC services into the specified # Registers or unregisters OpenRC services into the specified
# runlevel. # runlevel.
# #
# Arguments: $1 = action [run/targets] # Arguments: $1 = action [run/targets]
# $2 = target [post-install/pre-remove] # $2 = target [post-install/pre-remove]
# $3 = pkgname # $3 = pkgname
# $4 = version
# $5 = update [yes/no]
# #
initdir=etc/init.d ACTION="$1"
TARGET="$2"
PKGNAME="$3"
VERSION="$4"
UPDATE="$5"
case "$1" in initdir=etc/init.d
metadatadir=var/db/xbps/metadata/${PKGNAME}
case "$ACTION" in
targets) targets)
echo "post-install pre-remove" echo "post-install pre-remove"
;; ;;
@ -18,12 +27,9 @@ run)
[ ! -x sbin/rc-service ] && exit 0 [ ! -x sbin/rc-service ] && exit 0
[ -z "$openrc_services" ] && exit 1 [ -z "$openrc_services" ] && exit 1
target=$2 if [ "$TARGET" = "pre-remove" ]; then
if [ "$target" = "pre-remove" ]; then
text="Unr"
rcupdate_args="del" rcupdate_args="del"
elif [ "$target" = "post-install" ]; then elif [ "$TARGET" = "post-install" ]; then
text="R"
rcupdate_args="add" rcupdate_args="add"
else else
exit 1 exit 1
@ -33,22 +39,37 @@ run)
set -- ${openrc_services} set -- ${openrc_services}
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
if sbin/rc-service -e ${1}; then srv_restart=$metadatadir/.$1_srv_restart
# Stop the service if it's running. if [ "$TARGET" = "post-install" ]; then
if [ "$target" = "pre-remove" -a -f $initdir/$1 ]; then if [ -f $srv_restart ]; then
$initdir/$1 -q status # Restart service if it was running previously.
if [ $? -eq 0 ]; then $initdir/$1 start
$initdir/$1 stop rm -f $srv_restart
else
# Register service.
if sbin/rc-service -e ${1}; then
sbin/rc-update add ${1} ${2}
fi fi
fi fi
# (Un)register the service. else
echo "${text}egistering ${1} OpenRC service..." # While removing always stop the service if running.
sbin/rc-update ${rcupdate_args} ${1} ${2} $initdir/$1 -q status
if [ $? -eq 0 ]; then
$initdir/$1 stop
fi
#
# While upgrading a package, don't remove the service.
#
if [ "$UPDATE" = "yes" ]; then
touch -f $srv_restart
else
# Unregister the service.
sbin/rc-update del ${1} ${2}
fi
fi fi
unset srv_restart
shift; shift; shift; shift;
done done
sbin/rc-update -u
;; ;;
*) *)
exit 1 exit 1