forked from extern/zfs-auto-snapshot
Make logging work properly in the face of the RBAC changes
Refresh i.manifest and r.manifest from ON gate
This commit is contained in:
parent
4591fe27ea
commit
a924e083af
@ -3,9 +3,8 @@
|
|||||||
# CDDL HEADER START
|
# CDDL HEADER START
|
||||||
#
|
#
|
||||||
# The contents of this file are subject to the terms of the
|
# The contents of this file are subject to the terms of the
|
||||||
# Common Development and Distribution License, Version 1.0 only
|
# Common Development and Distribution License (the "License").
|
||||||
# (the "License"). You may not use this file except in compliance
|
# You may not use this file except in compliance with the License.
|
||||||
# with the License.
|
|
||||||
#
|
#
|
||||||
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
||||||
# or http://www.opensolaris.org/os/licensing.
|
# or http://www.opensolaris.org/os/licensing.
|
||||||
@ -21,17 +20,58 @@
|
|||||||
# CDDL HEADER END
|
# CDDL HEADER END
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
|
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
|
||||||
# Use is subject to license terms.
|
# Use is subject to license terms.
|
||||||
#
|
#
|
||||||
#ident "%Z%%M% %I% %E% SMI"
|
|
||||||
#
|
|
||||||
# i.manifest - smf(5) service manifest install class action script
|
# i.manifest - smf(5) service manifest install class action script
|
||||||
#
|
#
|
||||||
|
|
||||||
repfile=$PKG_INSTALL_ROOT/etc/svc/repository.db
|
repfile=$PKG_INSTALL_ROOT/etc/svc/repository.db
|
||||||
export repfile
|
export repfile
|
||||||
|
|
||||||
|
SVCCFG=/usr/sbin/svccfg
|
||||||
|
AWK=/usr/bin/awk
|
||||||
|
RM=/usr/bin/rm
|
||||||
|
CP=/usr/bin/cp
|
||||||
|
MV=/usr/bin/mv
|
||||||
|
CHMOD=/usr/bin/chmod
|
||||||
|
CHOWN=/usr/bin/chown
|
||||||
|
|
||||||
|
#
|
||||||
|
# Helper function. Handle services deathrow file.
|
||||||
|
# Arguments: $1:manifest file.
|
||||||
|
#
|
||||||
|
svc_deathrow()
|
||||||
|
{
|
||||||
|
TEMP=/tmp/svc_deathrow.$$
|
||||||
|
DEATHROW_FILE=${PKG_INSTALL_ROOT}/etc/svc/deathrow
|
||||||
|
#
|
||||||
|
# Services deathrow file handling, file format:
|
||||||
|
# <fmri>< ><manifest file>< ><package name>
|
||||||
|
# (field separator is a space character)
|
||||||
|
#
|
||||||
|
if [ -s ${DEATHROW_FILE} ]; then
|
||||||
|
#
|
||||||
|
# Manifest file could be from another Solaris version, bypass
|
||||||
|
# the service bundle and validation (we only need the fmris
|
||||||
|
# list). Calling svccfg inventory with SVCCFG_NOVALIDATE=1 is
|
||||||
|
# safe because there is no access to the alternate repository.
|
||||||
|
#
|
||||||
|
ENTITIES=`SVCCFG_NOVALIDATE=1 $SVCCFG inventory $1`
|
||||||
|
for fmri in $ENTITIES; do
|
||||||
|
#
|
||||||
|
# If fmri matches one in deathrow file, remove the
|
||||||
|
# line from the file.
|
||||||
|
#
|
||||||
|
>${TEMP}
|
||||||
|
$AWK "(\$1==\"$fmri\") \
|
||||||
|
{next}; {print}" ${DEATHROW_FILE} >>${TEMP} && \
|
||||||
|
$MV ${TEMP} ${DEATHROW_FILE}
|
||||||
|
$RM -f ${TEMP}
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# If the repository does not yet exist, create it from the appropriate seed. If
|
# If the repository does not yet exist, create it from the appropriate seed. If
|
||||||
# for some reason the seeds do not exist, svccfg(1M) will create the repository
|
# for some reason the seeds do not exist, svccfg(1M) will create the repository
|
||||||
@ -41,15 +81,13 @@ if [ ! -f $repfile ]; then
|
|||||||
if [ -n "$SUNW_PKG_INSTALL_ZONENAME" -a \
|
if [ -n "$SUNW_PKG_INSTALL_ZONENAME" -a \
|
||||||
"$SUNW_PKG_INSTALL_ZONENAME" != "global" ]; then
|
"$SUNW_PKG_INSTALL_ZONENAME" != "global" ]; then
|
||||||
[ -f $PKG_INSTALL_ROOT/lib/svc/seed/nonglobal.db ] && \
|
[ -f $PKG_INSTALL_ROOT/lib/svc/seed/nonglobal.db ] && \
|
||||||
/usr/bin/cp $PKG_INSTALL_ROOT/lib/svc/seed/nonglobal.db \
|
$CP $PKG_INSTALL_ROOT/lib/svc/seed/nonglobal.db $repfile
|
||||||
$repfile
|
|
||||||
else
|
else
|
||||||
[ -f $PKG_INSTALL_ROOT/lib/svc/seed/global.db ] && \
|
[ -f $PKG_INSTALL_ROOT/lib/svc/seed/global.db ] && \
|
||||||
/usr/bin/cp $PKG_INSTALL_ROOT/lib/svc/seed/global.db \
|
$CP $PKG_INSTALL_ROOT/lib/svc/seed/global.db $repfile
|
||||||
$repfile
|
|
||||||
fi
|
fi
|
||||||
/usr/bin/chmod 0600 $repfile
|
$CHMOD 0600 $repfile
|
||||||
/usr/bin/chown root:sys $repfile
|
$CHOWN root:sys $repfile
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -r $PKG_INSTALL_ROOT/etc/svc/volatile/repository_door ]; then
|
if [ ! -r $PKG_INSTALL_ROOT/etc/svc/volatile/repository_door ]; then
|
||||||
@ -59,17 +97,19 @@ if [ ! -r $PKG_INSTALL_ROOT/etc/svc/volatile/repository_door ]; then
|
|||||||
# cannot consistently handle dependent placement. Defer to next boot.
|
# cannot consistently handle dependent placement. Defer to next boot.
|
||||||
#
|
#
|
||||||
while read src dst; do
|
while read src dst; do
|
||||||
/usr/bin/cp -p $src $dst
|
$CP -p $src $dst
|
||||||
|
# deathrow handling
|
||||||
|
svc_deathrow $dst
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
#
|
#
|
||||||
# Local package install.
|
# Local package install.
|
||||||
#
|
#
|
||||||
while read src dst; do
|
while read src dst; do
|
||||||
/usr/bin/cp -p $src $dst
|
$CP -p $src $dst
|
||||||
|
|
||||||
[ "$PKG_INSTALL_ROOT" = "" -o "$PKG_INSTALL_ROOT" = "/" ] && \
|
[ "$PKG_INSTALL_ROOT" = "" -o "$PKG_INSTALL_ROOT" = "/" ] && \
|
||||||
SVCCFG_CHECKHASH=1 /usr/sbin/svccfg import $dst
|
SVCCFG_CHECKHASH=1 $SVCCFG import $dst
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -120,8 +120,6 @@ function schedule_snapshots {
|
|||||||
|
|
||||||
typeset FMRI=$1
|
typeset FMRI=$1
|
||||||
zfs_smf_props $FMRI
|
zfs_smf_props $FMRI
|
||||||
# functions we call need $LOG set.
|
|
||||||
export LOG=$logfile
|
|
||||||
|
|
||||||
# FIXME need work in here to actually validate the FMRI props
|
# FIXME need work in here to actually validate the FMRI props
|
||||||
typeset FILESYS="$fs_name"
|
typeset FILESYS="$fs_name"
|
||||||
@ -320,12 +318,12 @@ function check_missed_snapshots { # $INTERVAL $PERIOD $FMRI <repopulate cache>
|
|||||||
get_userprop_datasets
|
get_userprop_datasets
|
||||||
export snapshot_children=false
|
export snapshot_children=false
|
||||||
export fs_name="$SINGLE_LIST"
|
export fs_name="$SINGLE_LIST"
|
||||||
print_note "Checking for non-recursive missed // snapshots $SINGLE_LIST"
|
echo "Checking for non-recursive missed // snapshots $SINGLE_LIST"
|
||||||
check_missed_snapshots $INTERVAL $PERIOD $FMRI no_repopulate_cache
|
check_missed_snapshots $INTERVAL $PERIOD $FMRI no_repopulate_cache
|
||||||
|
|
||||||
export snapshot_children=true
|
export snapshot_children=true
|
||||||
export fs_name="$RECURSIVE_LIST"
|
export fs_name="$RECURSIVE_LIST"
|
||||||
print_note "Checking for recursive missed // snapshots $RECURSIVE_LIST"
|
echo "Checking for recursive missed // snapshots $RECURSIVE_LIST"
|
||||||
check_missed_snapshots $INTERVAL $PERIOD $FMRI no_repopulate_cache
|
check_missed_snapshots $INTERVAL $PERIOD $FMRI no_repopulate_cache
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@ -410,13 +408,6 @@ function take_snapshot {
|
|||||||
zfs_smf_props $FMRI
|
zfs_smf_props $FMRI
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# When taking snapshots, because we're running as a role
|
|
||||||
# and can't redirect our output through SMF, we don't have
|
|
||||||
# permissions to log to /var/svc/log, so we instead log
|
|
||||||
# to the role's home directory.
|
|
||||||
LOG_BASE=$(basename $logfile)
|
|
||||||
export LOG="$HOME/$LOG_BASE"
|
|
||||||
|
|
||||||
typeset DATE=$(date +%F-%H${SEP}%M)
|
typeset DATE=$(date +%F-%H${SEP}%M)
|
||||||
typeset FILESYS="$fs_name"
|
typeset FILESYS="$fs_name"
|
||||||
typeset KEEP=$keep
|
typeset KEEP=$keep
|
||||||
@ -609,21 +600,24 @@ function check_failure { # integer exit status, error message to display, be fat
|
|||||||
|
|
||||||
|
|
||||||
# A function we use to emit output. Right now, this goes to syslog via logger(1)
|
# A function we use to emit output. Right now, this goes to syslog via logger(1)
|
||||||
# but it would be much nicer to be able to print it to the svc log file for
|
# as well as being appended to a log file specified by $LOG. If this logfile
|
||||||
# each individual service instance - tricky because we're being called from
|
# variable doesn't exist, we simply echo the message to stdout, which will
|
||||||
# cron, most of the time and are detached from smf. Working around this by
|
# make it's way to the final log destination via SMF, since we'll always have
|
||||||
# appending to the $LOG file
|
# $LOG defined when being called from cron otherwise.
|
||||||
function print_log { # message to display
|
function print_log { # message to display
|
||||||
logger -t zfs-auto-snap -p daemon.notice $*
|
logger -t zfs-auto-snap -p daemon.notice $*
|
||||||
echo $(date) $* >> $LOG
|
if [ -z "$LOG" ] ; then
|
||||||
|
echo $*
|
||||||
|
else
|
||||||
|
echo $(date) $* >> $LOG
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Another function to emit output, this time checking to see if the
|
# Another function to emit output, this time checking to see if the
|
||||||
# user has set the service into verbose mode, otherwise, we print nothing
|
# user has set the service into verbose mode, otherwise, we print nothing
|
||||||
function print_note { # mesage to display
|
function print_note { # mesage to display
|
||||||
if [ "$VERBOSE" == "true" ] ; then
|
if [ "$VERBOSE" == "true" ] ; then
|
||||||
logger -t zfs-auto-snap -p daemon.notice $*
|
print_log $*
|
||||||
echo $(date) $* >> $LOG
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -913,9 +907,11 @@ function auto_include {
|
|||||||
# created above, where the argument is the FMRI containing properties we can
|
# created above, where the argument is the FMRI containing properties we can
|
||||||
# consult to in order to actually take the snapshot.
|
# consult to in order to actually take the snapshot.
|
||||||
|
|
||||||
|
|
||||||
|
# When called via SMF, several variables are set for us - SMF_FMRI being one
|
||||||
|
# we check for the existance of that
|
||||||
if [ -n "${SMF_FMRI}" ] ; then
|
if [ -n "${SMF_FMRI}" ] ; then
|
||||||
zfs_smf_props $SMF_FMRI
|
zfs_smf_props $SMF_FMRI
|
||||||
export LOG=$logfile
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# $1 start | stop | refresh | an FMRI that we want to take snapshots of.
|
# $1 start | stop | refresh | an FMRI that we want to take snapshots of.
|
||||||
@ -948,6 +944,10 @@ case "$1" in
|
|||||||
|
|
||||||
case $SMF_FMRI in
|
case $SMF_FMRI in
|
||||||
svc:/*)
|
svc:/*)
|
||||||
|
zfs_smf_props $SMF_FMRI
|
||||||
|
LOG_BASE=$(basename $logfile)
|
||||||
|
export LOG="$HOME/$LOG_BASE"
|
||||||
|
|
||||||
take_snapshot $SMF_FMRI
|
take_snapshot $SMF_FMRI
|
||||||
if [ $? -eq 0 ] ; then
|
if [ $? -eq 0 ] ; then
|
||||||
result=$SMF_EXIT_OK
|
result=$SMF_EXIT_OK
|
||||||
|
151
src/r.manifest
151
src/r.manifest
@ -3,9 +3,8 @@
|
|||||||
# CDDL HEADER START
|
# CDDL HEADER START
|
||||||
#
|
#
|
||||||
# The contents of this file are subject to the terms of the
|
# The contents of this file are subject to the terms of the
|
||||||
# Common Development and Distribution License, Version 1.0 only
|
# Common Development and Distribution License (the "License").
|
||||||
# (the "License"). You may not use this file except in compliance
|
# You may not use this file except in compliance with the License.
|
||||||
# with the License.
|
|
||||||
#
|
#
|
||||||
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
||||||
# or http://www.opensolaris.org/os/licensing.
|
# or http://www.opensolaris.org/os/licensing.
|
||||||
@ -21,14 +20,86 @@
|
|||||||
# CDDL HEADER END
|
# CDDL HEADER END
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
|
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
|
||||||
# Use is subject to license terms.
|
# Use is subject to license terms.
|
||||||
#
|
#
|
||||||
#ident "%Z%%M% %I% %E% SMI"
|
|
||||||
#
|
#
|
||||||
# r.manifest - smf(5) manifest remove class action script
|
# r.manifest - smf(5) manifest remove class action script
|
||||||
#
|
#
|
||||||
|
|
||||||
|
MFSTSCAN=/lib/svc/bin/mfstscan
|
||||||
|
SVCCFG=/usr/sbin/svccfg
|
||||||
|
SVCPROP=/usr/bin/svcprop
|
||||||
|
SVCADM=/usr/sbin/svcadm
|
||||||
|
AWK=/usr/bin/awk
|
||||||
|
CP=/usr/bin/cp
|
||||||
|
RM=/usr/bin/rm
|
||||||
|
|
||||||
|
# number of seconds to wait before killing processes
|
||||||
|
STOP_DELAY=60
|
||||||
|
|
||||||
|
#
|
||||||
|
# Helper function. Delete the manifest hash value.
|
||||||
|
# Arguments: $1: manifest file.
|
||||||
|
#
|
||||||
|
svc_delhash()
|
||||||
|
{
|
||||||
|
$SVCCFG delhash $1 >/dev/null 2>&1
|
||||||
|
if [ "$?" != "0" ];then
|
||||||
|
# this Solaris release doesn't have delhash command
|
||||||
|
pg_name=`$MFSTSCAN -t $1`
|
||||||
|
if $SVCPROP -q -p $pg_name smf/manifest; then
|
||||||
|
$SVCCFG -s smf/manifest delpg $pg_name
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Helper function. Handle services deathrow file.
|
||||||
|
# Arguments: $1:manifest file, $2:package name.
|
||||||
|
#
|
||||||
|
svc_deathrow()
|
||||||
|
{
|
||||||
|
DEATHROW_FILE=${PKG_INSTALL_ROOT}/etc/svc/deathrow
|
||||||
|
# remove alternate root from manifest path
|
||||||
|
manifest=`echo "${PKG_INSTALL_ROOT} $1" | $AWK \
|
||||||
|
'{ print substr($2, length($1)+1); }'`
|
||||||
|
#
|
||||||
|
# Services deathrow file handling, file format:
|
||||||
|
# <fmri>< ><manifest file>< ><package name>
|
||||||
|
# (field separator is a space character)
|
||||||
|
#
|
||||||
|
# Manifest file could be from another Solaris version, bypass the
|
||||||
|
# the service bundle and validation (we only need the fmris list).
|
||||||
|
# Calling svccfg inventory with SVCCFG_NOVALIDATE=1 is safe because
|
||||||
|
# there is no access to the alternate repository.
|
||||||
|
#
|
||||||
|
ENTITIES=`SVCCFG_NOVALIDATE=1 $SVCCFG inventory $1`
|
||||||
|
for fmri in $ENTITIES; do
|
||||||
|
# add to services deathrow file
|
||||||
|
echo ${fmri} ${manifest} $2 >> ${DEATHROW_FILE}
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
wait_disable() {
|
||||||
|
svcinst=$1
|
||||||
|
wait_time=$2
|
||||||
|
|
||||||
|
while [ ${nsec:=0} -lt $wait_time ]; do
|
||||||
|
state=`$SVCPROP -p restarter/state $svcinst`
|
||||||
|
if [ "$state" = "disabled" -o "$state" = "maintenance" ]; then
|
||||||
|
nstate=`$SVCPROP -p restarter/next_state $svcinst`
|
||||||
|
if [ "$nstate" = "none" ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
/usr/bin/sleep 1
|
||||||
|
nsec=`expr ${nsec} + 1`
|
||||||
|
done
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
if [ "$PKG_INSTALL_ROOT" != "" -a "$PKG_INSTALL_ROOT" != "/" ]; then
|
if [ "$PKG_INSTALL_ROOT" != "" -a "$PKG_INSTALL_ROOT" != "/" ]; then
|
||||||
#
|
#
|
||||||
# We can't safely disable the service in this case.
|
# We can't safely disable the service in this case.
|
||||||
@ -44,40 +115,72 @@ else
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
MFSTSCAN=/lib/svc/bin/mfstscan
|
|
||||||
SVCCFG=/usr/sbin/svccfg
|
|
||||||
SVCPROP=/usr/bin/svcprop
|
|
||||||
|
|
||||||
while read mfst; do
|
while read mfst; do
|
||||||
if [ "$smf_alive" = "yes" ]; then
|
if [ "$smf_alive" = "yes" ]; then
|
||||||
ENTITIES=`$SVCCFG inventory $mfst`
|
ENTITIES=`$SVCCFG inventory $mfst`
|
||||||
|
|
||||||
for fmri in $ENTITIES; do
|
for fmri in $ENTITIES; do
|
||||||
#
|
|
||||||
# Determine whether any of our instances are
|
|
||||||
# enabled.
|
|
||||||
#
|
|
||||||
en_p=`$SVCPROP -C -p general/enabled $fmri 2>/dev/null`
|
|
||||||
en_o=`$SVCPROP -C -p general_ovr/enabled $fmri 2>/dev/null`
|
|
||||||
|
|
||||||
if [ "$en_p" = "true" -o "$en_o" = "true" ]; then
|
# Determine whether fmri refers to an instance or a service.
|
||||||
echo "$fmri remains enabled; aborting"
|
$SVCPROP -p restarter/state $fmri >/dev/null 2>&1
|
||||||
exit 1
|
if [ $? -eq 1 ]; then
|
||||||
|
# this is a service fmri, all instances have been deleted
|
||||||
|
$SVCCFG delete $fmri 2>/dev/null
|
||||||
|
# process next instance
|
||||||
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$SVCCFG delete $fmri
|
#
|
||||||
|
# Try to disable the instance within a reasonable amount of time
|
||||||
|
# (eg. 60 secs). If it fails, forcibly delete the instance.
|
||||||
|
#
|
||||||
|
echo "Waiting up to $STOP_DELAY seconds for $fmri to stop..."
|
||||||
|
$SVCADM disable $fmri 2>/dev/null
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
wait_disable $fmri $STOP_DELAY
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
# the instance is disabled and can be safely deleted
|
||||||
|
$SVCCFG delete $fmri 2>/dev/null
|
||||||
|
# process next instance
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
echo "Failed to disable $fmri after $STOP_DELAY seconds"
|
||||||
|
else
|
||||||
|
echo "Failed to disable $fmri"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Force deleting $fmri"
|
||||||
|
|
||||||
|
ctid=`$SVCPROP -p restarter/contract $fmri 2>/dev/null`
|
||||||
|
tctid=`$SVCPROP -p restarter/transient_contract $fmri 2>/dev/null`
|
||||||
|
|
||||||
|
$SVCCFG delete -f $fmri
|
||||||
|
|
||||||
|
#
|
||||||
|
# Kill any remaining processes.
|
||||||
|
# pkill must occur after the delete to prevent startd
|
||||||
|
# from retrying the STOP method.
|
||||||
|
#
|
||||||
|
if [ -n "${tctid}" -a "${tctid}" -gt 1 ]; then
|
||||||
|
# kill the STOP method processes
|
||||||
|
/usr/bin/pkill -9 -c $tctid
|
||||||
|
fi
|
||||||
|
if [ -n "${ctid}" -a "${ctid}" -gt 1 ]; then
|
||||||
|
# kill any remaining running processes for the instance
|
||||||
|
/usr/bin/pkill -9 -c $ctid
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
#
|
#
|
||||||
# Delete the manifest hash value.
|
# Delete the manifest hash value.
|
||||||
#
|
#
|
||||||
pg_name=`$MFSTSCAN -t $mfst`
|
svc_delhash $mfst
|
||||||
if $SVCPROP -q -p $pg_name smf/manifest; then
|
else
|
||||||
$SVCCFG -s smf/manifest delpg $pg_name
|
# deathrow handling
|
||||||
fi
|
svc_deathrow $mfst $PKGINST
|
||||||
fi
|
fi
|
||||||
|
|
||||||
/usr/bin/rm $mfst
|
$RM -f $mfst
|
||||||
done
|
done
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
Loading…
Reference in New Issue
Block a user