|
1 #! /usr/bin/ksh93 |
|
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 # |
|
24 # Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. |
|
25 # |
|
26 |
|
27 # wait_until <time> <condition> |
|
28 # |
|
29 # Check if condition is true. If yes, return 0 immediately. If not, |
|
30 # keep checking it until either the condition becomes true or the |
|
31 # specified time have passed. Return 1 in later case. |
|
32 # |
|
33 wait_until () { |
|
34 total=$1 |
|
35 cond="$2" |
|
36 |
|
37 i=0 |
|
38 while (( i < total )); do |
|
39 eval $cond > /dev/null |
|
40 (( $? == 0 )) && return 0 |
|
41 sleep 1 |
|
42 i=$(( i + 1 )) |
|
43 done |
|
44 return 1 |
|
45 } |
|
46 |
|
47 source /lib/svc/share/smf_include.sh |
|
48 |
|
49 typeset -r EJABBERDCTL=/usr/sbin/ejabberdctl |
|
50 |
|
51 case "$1" in |
|
52 start) |
|
53 ${EJABBERDCTL} start 2>&1 |
|
54 wait_until 60 "${EJABBERDCTL} status | grep 'is running'" |
|
55 ;; |
|
56 stop) |
|
57 ${EJABBERDCTL} stop 2>&1 |
|
58 wait_until 60 "${EJABBERDCTL} status | grep 'nodedown'" |
|
59 ;; |
|
60 *) |
|
61 print "Usage: $0 {start|stop}" |
|
62 exit 1 |
|
63 ;; |
|
64 esac |
|
65 |
|
66 # not reached |