diff options
-rw-r--r-- | Makefile | 7 | ||||
-rw-r--r-- | NEWS | 19 | ||||
-rwxr-xr-x | add-service | 81 | ||||
-rwxr-xr-x | add-syslog | 11 | ||||
-rwxr-xr-x | del-service | 49 | ||||
-rwxr-xr-x | del-syslog | 11 | ||||
-rw-r--r-- | migrate-service | 53 | ||||
-rwxr-xr-x | postun-unit | 40 | ||||
-rw-r--r-- | rpm-helper.macros.in | 22 |
9 files changed, 253 insertions, 40 deletions
@@ -1,11 +1,12 @@ PACKAGE = rpm-helper -VERSION = 0.23.1 -SVNPATH = svn+ssh://svn.mandriva.com/svn/soft/rpm/$(PACKAGE) +VERSION = 0.24.1 +SVNPATH = svn+ssh://svn.mageia.org/svn/soft/rpm/$(PACKAGE) SCRIPT_FILES = add-user del-user add-service del-service create-file \ add-group del-group add-shell del-shell verify-shell \ add-syslog del-syslog add-webapp del-webapp \ - get-password create-ssl-certificate + get-password create-ssl-certificate \ + migrate-service postun-unit MACROS_FILES = rpm-helper.macros CONF_FILES = ssl TEST_FILES = t/*.t @@ -1,3 +1,22 @@ +2011-03-07 Andrey Borzenkov <arvidjaar@gmail.com> 0.23.7 + * avoid reloading systemd twice with new chkconfig + +2011-01-25 Eugeni Dodonov <eugeni@mandriva.com 0.23.6 + * Fix typo in del-service which made scriplet fail + +2011-01-25 Eugeni Dodonov <eugeni@mandriva.com 0.23.5 + * Fix typo in add-service which made scriplet fail + +2011-01-25 nanardon <nanardon@mandriva.org> 0.23.4 + * make add/del-syslog code more generic + * Reload systemd daemon when removing services. + +2011-01-23 Eugeni Dodonov <eugeni@mandriva.com> 0.23.3 + * fix typo in services removal (#62278) + +2011-01-23 Eugeni Dodonov <eugeni@mandriva.com> 0.23.2 + * add systemd support for services addition/removal (#62278) + 2010-05-29 Guillaume Rousse <guillomovitch@mandriva.org> 0.23.1 * force group creation when creating user, whatever /etc/login.defs says, to ensure expected group ownership (fix #59327) diff --git a/add-service b/add-service index 39c6607..a267439 100755 --- a/add-service +++ b/add-service @@ -3,31 +3,52 @@ # Project : Mandriva Linux # Module : rpm-helper # File : add-service -# Version : $Id: add-service 265147 2010-01-23 18:03:02Z guillomovitch $ -# Author : Frederic Lepied +# Version : $Id: add-service 272144 2011-03-20 18:42:29Z bor $ +# Authors : Frederic Lepied, Andrey Borzenkov # Created On : Mon Jul 8 08:14:34 2002 # Purpose : helper script for rpm scriptlets to add a # service. #--------------------------------------------------------------- -if [ $# != 3 ]; then - echo "usage: $0 <pkg name> <number installed> <service name>" 1>&2 +if [ x$1 = x--no-sysv ]; then + do_sysv=no + shift +else + do_sysv=yes +fi + +if [ $# -lt 3 ]; then + echo "usage: $0 [--no-sysv] <pkg name> <number installed> [<service name>] <unit name> ..." 1>&2 exit 1 fi pkg=$1 # name of the package num=$2 # number of packages installed -srv=$3 # name of the service +if [ $do_sysv = yes ]; then + srv=$3 # name of the SysV script + shift 3 +else + srv= + shift 2 +fi +units="$*" # systemd units +units_to_enable= # units enabled by msec add_chkconfig_service() { - srv=$1 - - /sbin/chkconfig --add $srv + if [ -n "$units_to_enable" ]; then + /bin/systemctl --quiet enable $units_to_enable + fi + if [ -n "$srv" ]; then + /sbin/chkconfig --add $srv + else + exit 0 + fi if [ -r /etc/sysconfig/system ]; then . /etc/sysconfig/system fi + # TODO what to do with system units here? if [ -z "$ADD_SERVICES_TO_CURRENT_PROFILE_ONLY" ]; then # add the service to all the profiles at once if [ -d /etc/netprofile/profiles/default/services ]; then @@ -53,24 +74,48 @@ add_service() { LIST=/etc/security/msec/server.$SECURE_LEVEL fi + # This is half-hearted support for msec: we check "srv" for a unit + # with name "srv.service". This should account for most(?) common + # case when SysV script srv is replaced by single unit srv.service + # If SysV name was supplied, we assume units are equivalent and do + # not need to be checked. + # TODO should msec support full unit name? if [ -f $LIST ]; then - if grep -q "^${srv}$" $LIST ; then - add_chkconfig_service $srv + if [ -n "$srv" ]; then + if fgrep -qx "${srv}" $LIST; then + units_to_enable="$units" + else + srv= + fi + else + for i in $units; do + [ $i != ${i%.service} ] && ! fgrep -qx ${i%.service} $LIST && continue + units_to_enable="$units_to_enable $i" + done fi else - # Low security: install all the services - add_chkconfig_service $srv + units_to_enable="$units" fi + + add_chkconfig_service } if [ $num = 1 ]; then # First install mode add_service else - # Upgrade mode + # Upgrade mode. systemd units are restarted in postun + [ -n "$srv" ] || exit 0 # if the service is activated, add it again to be able to handle - # changes in start/stop levels + # changes in start/stop levels. This does not change enabled/disabled + # state, so we do not do it for systemd where dependencies are handled + # automatically. + + # Restart only SysV services here only if no additional systemd + # units are defined or systemd is not active. Otherwise user is expected + # to add postun script that handles systemd units. + set -- /etc/rc3.d/S??$srv if [ $# -gt 1 ]; then echo 1>&2 "add-service: Error: $srv appears multiple times: $*" @@ -80,9 +125,11 @@ else /sbin/chkconfig --add $srv fi - # restart the service if already running - if [ -f /var/lock/subsys/$srv ]; then - /sbin/service $srv restart > /dev/null || : + if [ -z "$units" ] || ! /bin/mountpoint -q /sys/fs/cgroup/systemd; then + # restart the service if already running + if [ -f /var/lock/subsys/$srv ]; then + /sbin/service $srv restart > /dev/null || : + fi fi fi @@ -1,6 +1,6 @@ #!/usr/bin/perl # rpm helper scriptlet to add an entry into default syslog implementation -# $Id: add-syslog 265807 2010-02-04 19:58:23Z guillomovitch $ +# $Id: add-syslog 271805 2011-01-25 14:57:43Z nanardon $ use Getopt::Std; use strict; @@ -44,15 +44,16 @@ EOF die "maximum priority '$max' lower than minimum priority '$min'" if $min && $max && ($priorities{$max} < $priorities{$min}); - open(my $fh, '<', '/etc/mandriva-release') - or die "can't open /etc/mandriva-release: $!"; + my $release_file = '/etc/release'; + open(my $fh, '<', $release_file) + or die "can't open $release_file: $!"; my $line = <$fh>; - $line =~ /^Mandriva Linux release (\d\d\d\d\.\d)/; + $line =~ /^Mageia release (\d\d\d\d\.\d)/; my $release = $1; close($fh); # add an entry to default syslog implementation, if installed - if (version->parse($release) < version->parse("2010.1")) { + if ($release && version->parse($release) < version->parse("2010.1")) { add_sysklogd_entry($package, $source, $dest, $facility, $min, $max) if -f '/etc/init.d/syslog'; } else { diff --git a/del-service b/del-service index 34c2328..8e7ddb7 100755 --- a/del-service +++ b/del-service @@ -3,27 +3,62 @@ # Project : Mandriva Linux # Module : rpm-helper # File : del-service -# Version : $Id: del-service 263135 2009-10-30 16:58:08Z blino $ -# Author : Frederic Lepied +# Version : $Id: del-service 272144 2011-03-20 18:42:29Z bor $ +# Authors : Frederic Lepied, Andrey Borzenkov # Created On : Tue Jul 9 08:11:26 2002 # Purpose : helper script for rpm scriptlets to remove a # service. #--------------------------------------------------------------- -if [ $# != 3 ]; then - echo "usage: $0 <pkg name> <number installed> <service name>" 1>&2 +if [ x$1 = x--no-sysv ]; then + do_sysv=no + shift +else + do_sysv=yes +fi + +if [ $# -lt 3 ]; then + echo "usage: $0 [--no-sysv] <pkg name> <number installed> [<service name>] <unit name> ..." 1>&2 exit 1 fi pkg=$1 # name of the package num=$2 # number of packages installed -srv=$3 # name of the service +if [ $do_sysv = yes ]; then + srv=$3 # name of the SysV script + shift 3 +else + srv= + shift 2 +fi +units="$*" # systemd units +units_to_remove= + if [ $num = 0 ]; then + if [ -z "$DURING_INSTALL" ]; then - /sbin/service $srv stop > /dev/null || : + if [ -n "$units" ]; then + if /bin/mountpoint -q /sys/fs/cgroup/systemd; then + /bin/systemctl stop $units + fi + elif [ -n "srv" ]; then + /sbin/service $srv stop > /dev/null || : + fi + fi + + [ -n "$units" ] && /bin/systemctl --no-reload --quiet disable $units + [ -n "$srv" ] && /sbin/chkconfig --del $srv + + # Yes - this is very ugly workaround. chkconfig --del does daemon-reload, + # but initscript is still there, so it remains loaded. Remove file and + # reload again. Systemd units are supposed to provide postun script + + if [ -n "$srv" -a -z "$units" ] && \ + /bin/mountpoint -q /sys/fs/cgroup/systemd; then + /bin/rm -f /etc/rc.d/init.d/$srv + /bin/systemctl daemon-reload fi - /sbin/chkconfig --del $srv fi # del-service ends here @@ -1,6 +1,6 @@ #!/usr/bin/perl # rpm helper scriptlet to remove a syslog entry (sysklogd and syslog-ng) -# $Id: del-syslog 265808 2010-02-04 19:58:44Z guillomovitch $ +# $Id: del-syslog 271805 2011-01-25 14:57:43Z nanardon $ use strict; main(@ARGV) unless caller(); @@ -14,14 +14,15 @@ EOF # don't do anything for upgrade exit(0) if $number == 1; - open(my $fh, '<', '/etc/mandriva-release') - or die "can't open /etc/mandriva-release: $!"; + my $release_file = '/etc/release'; + open(my $fh, '<', $release_file) + or die "can't open $release_file: $!"; my $line = <$fh>; - $line =~ /^Mandriva Linux release (\d\d\d\d\.\d)/; + $line =~ /^Mageia release (\d\d\d\d\.\d)/; my $release = $1; close($fh); - if (version->parse($release) < version->parse("2010.1")) { + if ($release && version->parse($release) < version->parse("2010.1")) { del_sysklogd_entry($package); } else { del_rsyslog_entry($package); diff --git a/migrate-service b/migrate-service new file mode 100644 index 0000000..de08435 --- /dev/null +++ b/migrate-service @@ -0,0 +1,53 @@ +#!/bin/sh +#--------------------------------------------------------------- +# Project : Mandriva Linux +# Module : rpm-helper +# File : migrate-service +# Version : $Id$ +# Authors : Andrey Borzenkov +# Created On : Sat Mar 12 18:37:00 2011 +# Purpose : helper script for rpm scriptlets to migrate +# from SysV script to systemd unit. +#--------------------------------------------------------------- + +if [ $# -lt 3 ]; then + echo "usage: $0 {pre|post} <service name> <unit name> ..." 1>&2 + exit 1 +fi + +phase=$1 # pre/post +srv=$2 # name of the SysV script +shift 2 # systemd units + +if [ $phase = pre ]; then + # create flag that service was active and stop it + # As we are booted under systemd, we can just as well ask it ... + /bin/rm -f /tmp/systemd-migrate-active-$srv + if /bin/mountpoint -q /sys/fs/cgroup/systemd; then + active=$(/bin/systemctl show --no-pager -p ActiveState $srv.service 2> /dev/null) + if [ "${active#ActiveState=}" = active ]; then + /bin/touch /tmp/systemd-migrate-active-$srv + /bin/systemctl stop $srv.service + fi + fi + + # enable units if service was active in run-levels 3 or 5. + # This loosely corresponds to systemctl is-enabled. We assume, that + # units do include correct [Install] entries. + if /sbin/chkconfig --no-redirect --level=3 $srv || \ + /sbin/chkconfig --no-redirect --level=5 $srv; then + /bin/systemctl --no-reload --quiet enable "$@" || : + fi +else + # Reload daemon after old package was removed + # Restart new units if old SysV script was started. + if /bin/mountpoint -q /sys/fs/cgroup/systemd; then + /bin/systemctl daemon-reload + if [ -f /tmp/systemd-migrate-active-$srv ]; then + /bin/systemctl start "$@" + fi + fi + /bin/rm -f /tmp/systemd-migrate-active-$srv +fi + +# migrate-service ends here diff --git a/postun-unit b/postun-unit new file mode 100755 index 0000000..dfc4b82 --- /dev/null +++ b/postun-unit @@ -0,0 +1,40 @@ +#!/bin/sh +#--------------------------------------------------------------- +# Project : Mandriva Linux +# Module : rpm-helper +# File : postun-unit +# Version : $Id$ +# Authors : Andrey Borzenkov +# Created On : Sat Mar 12 18:05:00 2011 +# Purpose : helper script for rpm scriptlets to remove a +# systemd unit. +#--------------------------------------------------------------- + +# Reload systemd configuration and try to restart units +# It has to be done in postun because package removal may delete +# some links and we need to inform systemd about it + +/bin/mountpoint -q /sys/fs/cgroup/systemd || exit 0 + +if [ $# -lt 3 ]; then + echo "usage: $0 <pkg name> <number installed> <unit> ..." 1>&2 + exit 1 +fi + +pkg=$1 # name of the package +num=$2 # number of packages installed +shift 2 # systemd units + +/bin/systemctl daemon-reload + +if [ $num -ge 1 ]; then + if [ -z "$DURING_INSTALL" ]; then + # New package may have removed some units so restart will + # fail for them; catch it. + # TODO find a way to pass parameters from current packages + # into script installed by previous version + /bin/systemctl try-restart "$@" || : + fi +fi + +# postun-unit ends here diff --git a/rpm-helper.macros.in b/rpm-helper.macros.in index 2ea187f..cfcf2e5 100644 --- a/rpm-helper.macros.in +++ b/rpm-helper.macros.in @@ -1,4 +1,4 @@ -# $Id: rpm-helper.macros.in 265742 2010-02-03 22:47:17Z guillomovitch $ +# $Id: rpm-helper.macros.in 272144 2011-03-20 18:42:29Z bor $ %_rpm_helper_dir @pkgdatadir@ @@ -15,11 +15,11 @@ # initscripts macros %_add_service_helper %_rpm_helper_dir/add-service -%_post_service() %_add_service_helper %{name} $1 %{1} \ +%_post_service() %_add_service_helper %{name} $1 %{*} \ %{nil} %_del_service_helper %_rpm_helper_dir/del-service -%_preun_service() %_del_service_helper %{name} $1 %{1} \ +%_preun_service() %_del_service_helper %{name} $1 %{*} \ %{nil} %_add_user_helper %_rpm_helper_dir/add-user @@ -65,3 +65,19 @@ %_postun_webapp() %_del_webapp_helper %{name} $1 \ %{nil} +# systemd support +%_migrate_service_helper %_rpm_helper_dir/migrate-service +%_systemd_migrate_service_pre() %_migrate_service_helper pre %{*} \ +%{nil} +%_systemd_migrate_service_post() %_migrate_service_helper post %{*} \ +%{nil} + +%_post_unit() %_add_service_helper --no-sysv %{name} $1 %{*} \ +%{nil} + +%_preun_unit() %_del_service_helper --no-sysv %{name} $1 %{*} \ +%{nil} + +%_postun_unit_helper %_rpm_helper_dir/postun-unit +%_postun_unit() %_postun_unit_helper %{name} $1 %{*} \ +%{nil} |