[csw-maintainers] cswinitsmf and alternate root's
Ben Walton
bwalton at opencsw.org
Thu Jul 26 16:07:38 CEST 2012
Hi All,
I was updating some csw packages in an alternate boot environment last
night and hit a snag with services handled by cswinitsmf. It was
updating service states in the live boot environment, not the
alternate.
I think the following patch addresses this, but I'd appreciate more
eyes on it.
Thanks
-Ben
Index: CSWcswclassutils.i.cswinitsmf
===================================================================
--- CSWcswclassutils.i.cswinitsmf (revision 18857)
+++ CSWcswclassutils.i.cswinitsmf (working copy)
@@ -23,6 +23,7 @@
# 2009-08-10 Fix autoenable bug (Bug ID 0003785)
# 2010-10-25 Fix grep bug in FMRI 'dot in name' detection (Bug ID 0004588)
# 2011-04-21 Read absolute state value instead of defaulting to enabled
+# 2012-07-26 Better handle -R (alt root) for BE patching, etc. -bw
DEBUG= # clear to disable debug, set to anything to enable
SVCDIR=/var/opt/csw/svc
@@ -110,11 +111,11 @@
testpath=$SVCDIR/manifest
for i in `echo $FMRI | sed 's/\// /g'`; do
testpath=$testpath/$i
- if [ ! -d $testpath ]; then
+ if [ ! -d $PKG_INSTALL_ROOT/$testpath ]; then
echo Creating $testpath ...
- /usr/bin/mkdir $testpath
- /usr/bin/chown root:bin $testpath
- /usr/bin/chmod 755 $testpath
+ /usr/bin/mkdir $PKG_INSTALL_ROOT/$testpath
+ /usr/bin/chown root:bin $PKG_INSTALL_ROOT/$testpath
+ /usr/bin/chmod 755 $PKG_INSTALL_ROOT/$testpath
/usr/sbin/installf -c cswinitsmf $PKGINST $testpath d 755 root bin
fi
done
@@ -122,10 +123,10 @@
echo FMRI: $FMRI
fi
echo Creating service script in $SVCDIR/method/svc-$service ...
- /usr/bin/ln -s $dest $SVCDIR/method/svc-$service
+ /usr/bin/ln -s $dest $PKG_INSTALL_ROOT/$SVCDIR/method/svc-$service
/usr/sbin/installf -c cswinitsmf $PKGINST $SVCDIR/method/svc-$service=$dest s
- /usr/bin/chmod 755 $SVCDIR/method/svc-$service
- /usr/bin/chown root:bin $SVCDIR/method/svc-$service
+ /usr/bin/chmod 755 $PKG_INSTALL_ROOT/$SVCDIR/method/svc-$service
+ /usr/bin/chown root:bin $PKG_INSTALL_ROOT/$SVCDIR/method/svc-$service
MANIFEST=
if [ "`grep '^#MANIFEST' $dest`" ]; then
@@ -136,7 +137,7 @@
echo Creating manifest ...
# Add first part of manifest
MANIFEST=$SVCDIR/manifest/$FMRI/$service.xml
- cat > $MANIFEST << EOF
+ cat > $PKG_INSTALL_ROOT/$MANIFEST << EOF
<?xml version='1.0'?>
<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
<!--
@@ -185,8 +186,8 @@
EOF
# Add restart option to manifest if service script supports it
- if [ "`/usr/bin/egrep 'restart.?\)' $SVCDIR/method/svc-$service`" ]; then
- cat >> $MANIFEST << EOF
+ if [ "`/usr/bin/egrep 'restart.?\)' $PKG_INSTALL_ROOT/$SVCDIR/method/svc-$service`" ]; then
+ cat >> $PKG_INSTALL_ROOT/$MANIFEST << EOF
<exec_method
type='method'
name='restart'
@@ -198,8 +199,8 @@
fi
# Add refresh option to manifest if service script supports it
- if [ "`/usr/bin/egrep 'refresh.?\)' $SVCDIR/method/svc-$service`" ]; then
- cat >> $MANIFEST << EOF
+ if [ "`/usr/bin/egrep 'refresh.?\)' $PKG_INSTALL_ROOT/$SVCDIR/method/svc-$service`" ]; then
+ cat >> $PKG_INSTALL_ROOT/$MANIFEST << EOF
<exec_method
type='method'
name='refresh'
@@ -211,14 +212,14 @@
fi
# Add last part of manifest
- cat >> $MANIFEST << EOF
+ cat >> $PKG_INSTALL_ROOT/$MANIFEST << EOF
</service>
</service_bundle>
EOF
/usr/sbin/installf -c cswinitsmf $PKGINST $MANIFEST f 644 root bin
- /usr/bin/chmod 644 $MANIFEST
- /usr/bin/chown root:bin $MANIFEST
+ /usr/bin/chmod 644 $PKG_INSTALL_ROOT/$MANIFEST
+ /usr/bin/chown root:bin $PKG_INSTALL_ROOT/$MANIFEST
else
# Custom manifest
echo Using custom manifest ...
@@ -230,8 +231,10 @@
# Register with SMF
echo Configuring service in SMF ...
- /usr/sbin/svccfg import $MANIFEST > /dev/null 2>&1
- /usr/sbin/svcadm disable svc:/$FMRI/$service > /dev/null 2>&1
+ chroot ${PKG_INSTALL_ROOT:-/} /usr/sbin/svccfg import $MANIFEST > /dev/null 2>&1
+ if [ "${PKG_INSTALL_ROOT:-/}" != "/" ]; then
+ /usr/sbin/svcadm disable svc:/$FMRI/$service > /dev/null 2>&1
+ fi
echo $PKGINST is using Service Management Facility. The FMRI is svc:/$FMRI/$service:default
# Start service
@@ -244,7 +247,7 @@
# enable the service if it was enabled before, OR if $daemon = yes and AUTOENABLE is set
# previous SMF state always takes precedence
# note: autoenable_daemons and autoenable_$service controls $daemon, $AUTOENABLE is set by the package itself
- if [ "$SMF_STATE" = "enabled" ] || [ "$daemon" = "yes" -a "$AUTOENABLE" != "no" -a "$AUTOENABLE" != "false" ]; then
+ if [ "$SMF_STATE" = "enabled" ] || [ "$daemon" = "yes" -a "$AUTOENABLE" != "no" -a "$AUTOENABLE" != "false" -a "${PKG_INSTALL_ROOT:-/}" = "/" ]; then
echo "Clearing svc:/$FMRI/$service in case it's in the maintenance state..."
/usr/sbin/svcadm clear svc:/$FMRI/$service > /dev/null 2>&1
echo Enabling svc:/$FMRI/$service ...
@@ -257,7 +260,7 @@
# Create link to /etc/init.d
echo /etc/init.d/$service
- /usr/bin/ln -s $dest /etc/init.d/$service
+ /usr/bin/ln -s $dest ${PKG_INSTALL_ROOT}/etc/init.d/$service
/usr/sbin/installf -c cswinitsmf $PKGINST /etc/init.d/$service=$dest s
# Create rc-symlinks if enabled
@@ -301,12 +304,12 @@
for i in $RC_KLEV; do
echo /etc/rc$i.d/K$RC_KNUM$service
/usr/sbin/installf -c cswinitsmf $PKGINST /etc/rc$i.d/K$RC_KNUM$service=/etc/init.d/$service s
- /bin/ln -s /etc/init.d/$service /etc/rc$i.d/K$RC_KNUM$service
+ /bin/ln -s /etc/init.d/$service ${PKG_INSTALL_ROOT}/etc/rc$i.d/K$RC_KNUM$service
done
for i in $RC_SLEV; do
echo /etc/rc$i.d/S$RC_SNUM$service
/usr/sbin/installf -c cswinitsmf $PKGINST /etc/rc$i.d/S$RC_SNUM$service=/etc/init.d/$service s
- /bin/ln -s /etc/init.d/$service /etc/rc$i.d/S$RC_SNUM$service
+ /bin/ln -s /etc/init.d/$service ${PKG_INSTALL_ROOT}/etc/rc$i.d/S$RC_SNUM$service
done
# Start service
@@ -317,8 +320,10 @@
if [ "$AUTOENABLE" != "no" -a "$AUTOENABLE" != "false" ]; then
echo Starting $service ...
# fix permissions temporarily since 644 is used until verification
- /usr/bin/chmod 744 /etc/init.d/$service
- /etc/init.d/$service start > /dev/null 2>&1
+ /usr/bin/chmod 744 ${PKG_INSTALL_ROOT}/etc/init.d/$service
+ if [ "${PKG_INSTALL_ROOT:-/}" = "/" ]; then
+ /etc/init.d/$service start > /dev/null 2>&1
+ fi
fi
fi
fi
--
Ben Walton
Systems Programmer - CHASS
University of Toronto
C:416.407.5610 | W:416.978.4302
More information about the maintainers
mailing list