5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
23 # Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
25 # A rather simple SMF method script for
26 # svc:/application/time-slider:default
27 # It's sole purpose is to set the correct SMF property value of it's
28 # direct "auto-snapshot:<schedule>" dependencies: zfs/fs-name = '//'
30 . /lib/svc/share/smf_include.sh
32 RSYNC_PROG="/usr/lib/time-slider/plugins/rsync/rsync-backup"
34 # This function sets the appropriate svc configuration property for all
35 # dependent auto-snapshot:<schedule> instances if necessary
36 function update_service_props {
37 DEPENDENCIES=$(svcs -d -H -o fmri $SMF_FMRI|grep auto-snapshot)
38 for dependency in ${DEPENDENCIES} ; do
39 if [ "$(svcprop -p zfs/fs-name $dependency)" != "//" ] ; then
40 svccfg -s $dependency setprop zfs/fs-name = astring: "//"
41 svcadm refresh $dependency
46 # Given the exit status of a command, an integer, 0 if the command completed
47 # without errors. If the command exited with errors we degrade the
48 # state of this service into maintenance mode. If a 3rd argument is presented
49 # we don't degrade the service. We also log an error message as passed into
52 function check_failure { # integer exit status, error message to display, be fatal
58 if [ $RESULT -ne 0 ] ; then
59 print_log "Error: $ERR_MSG"
60 print_log "Moving service $SMF_FMRI to maintenance mode."
61 if [ -z "${NON_FATAL}" ] ; then
62 print_log "Moving service $SMF_FMRI to maintenance mode."
63 svcadm mark maintenance $SMF_FMRI
69 # A function we use to emit output. Right now, this goes to syslog via logger(1)
70 function print_log { # message to display
71 logger -t time-slider -p daemon.notice $*
75 function add_rsync_cronjob {
76 # Call every 30 minutes, 15 and 45 minutes after the hour.
77 SCHEDULE="15,45 * * * *"
79 # adding a cron job is essentially just looking for an existing entry,
80 # removing it, and appending a new one. Neato.
81 crontab -l | grep -v "${RSYNC_PROG} $SMF_FMRI" \
82 > /tmp/saved-crontab.$$
84 echo "${SCHEDULE} ${RSYNC_PROG} $SMF_FMRI" \
85 >> /tmp/saved-crontab.$$
87 crontab /tmp/saved-crontab.$$
88 check_failure $? "Unable to add cron job!"
90 rm /tmp/saved-crontab.$$
94 function remove_rsync_cronjob {
96 crontab -l | grep -v "${RSYNC_PROG} $SMF_FMRI$" \
97 > /tmp/saved-crontab.$$
98 crontab /tmp/saved-crontab.$$
99 check_failure $? "Unable to unschedule cron job for $SMF_FMRI"
101 rm /tmp/saved-crontab.$$
103 # finally, check our status before we return
104 STATE=$(svcprop -p restarter/state $SMF_FMRI)
105 if [ "${STATE}" == "maintenance" ] ; then
114 #FIXME - This HAS to be == rsync-trigger program
115 PLUGIN_CMD="$(svcprop -p plugin/trigger_command $SMF_FMRI)"
116 if [ $? -ne 0 ] ; then
117 echo "Unable to obtain plugin invocation command"
118 exit $SMF_EXIT_ERR_CONFIG
121 if [ ! -x $PLUGIN_CMD ] ; then
122 echo "\"$PLUGIN_CMD\" is not an executable path"
123 exit $SMF_EXIT_ERR_CONFIG
131 echo "Command line invocation of ${0} unsupported."
132 echo "This script is intended for smf(5) invocation only"
133 exit $SMF_EXIT_ERR_NOSMF