Update README.md to specify the python requirements
[time-slider.git] / lib / svc / method / time-slider
1 #!/bin/ksh
2 #
3 # CDDL HEADER START
4 #
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.
8 #
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.
13 #
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]
19 #
20 # CDDL HEADER END
21 #
22 #
23 # Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24 # Use is subject to license terms.
25 #
26 # ident "%Z%%M% %I%     %E% SMI"
27
28 . /lib/svc/share/smf_include.sh
29
30
31 # Given the exit status of a command, an integer, 0 if the command completed
32 # without errors. If the command exited with errors we degrade the
33 # state of this service into maintenance mode. If a 3rd argument is presented
34 # we don't degrade the service. We also log an error message as passed into
35 # this function.
36 #
37 function check_failure { # integer exit status, error message, non-fatal flag
38
39         typeset RESULT=$1
40         typeset ERR_MSG=$2
41         typeset NON_FATAL=$3
42
43         if [ $RESULT -ne 0 ] ; then
44             print_log "Error: $ERR_MSG"
45             if [ -z "${NON_FATAL}" ] ; then
46                 print_log "Moving service $SMF_FMRI to maintenance mode."
47                 svcadm mark maintenance $SMF_FMRI
48             fi
49         fi
50
51 }
52
53
54 # A function we use to emit output. Right now, this goes to syslog via logger(1)
55 # as well as being echoed to stdout which will result in it being picked up by
56 # SMF if the $LOG variable is null.
57 #
58 function print_log { # message to display
59         logger -t time-slider -p daemon.notice $*
60         echo $*
61 }
62
63 # this function removes any left over cron jobs belonging to
64 # legacy zfs-auto-snapshot
65 #
66 function remove_legacy_cronjobs {
67
68         crontab -l | grep -v "/lib/svc/method/zfs-auto-snapshot" \
69             > /tmp/saved-crontab.$$
70
71         crontab /tmp/saved-crontab.$$
72         check_failure $? "Unable to remove legacy zfs-auto-snaphot cron jobs" "NON_FATAL"
73
74         rm /tmp/saved-crontab.$$
75
76 }
77
78 case "$1" in
79 'start')
80         remove_legacy_cronjobs
81
82         [ ! -x /usr/lib/time-sliderd ] && exit $SMF_EXIT_ERR_CONFIG
83
84         /usr/lib/time-sliderd
85         err=$?
86         if [ $err -ne 0 ]; then
87                 echo "Time Slider failed to start: error $err"
88                 exit $SMF_EXIT_ERR_FATAL
89         fi
90         ;;
91 *)
92         echo "Usage: $0 { start }"
93         exit $SMF_EXIT_ERR_FATAL 
94         ;;
95 esac
96
97 exit $SMF_EXIT_OK