components/samba/samba/Solaris/samba.sh
author Vladimir Marek <Vladimir.Marek@oracle.com>
Thu, 31 Jan 2013 19:36:21 +0100
changeset 1140 501d8b6b07c2
parent 878 f5bfc829326f
child 1396 2c75b46fc80a
permissions -rw-r--r--
15758029 SUNBT7116639 Winbind SMF service should detect its failure
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
878
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
     1
#!/sbin/sh
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
     2
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
     3
#
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
     4
# CDDL HEADER START
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
     5
#
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
     6
# The contents of this file are subject to the terms of the
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
     7
# Common Development and Distribution License (the "License").
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
     8
# You may not use this file except in compliance with the License.
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
     9
#
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    10
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    11
# or http://www.opensolaris.org/os/licensing.
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    12
# See the License for the specific language governing permissions
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    13
# and limitations under the License.
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    14
#
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    15
# When distributing Covered Code, include this CDDL HEADER in each
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    16
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    17
# If applicable, add the following below this CDDL HEADER, with the
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    18
# fields enclosed by brackets "[]" replaced with your own identifying
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    19
# information: Portions Copyright [yyyy] [name of copyright owner]
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    20
#
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    21
# CDDL HEADER END
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    22
#
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    23
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    24
#
1140
501d8b6b07c2 15758029 SUNBT7116639 Winbind SMF service should detect its failure
Vladimir Marek <Vladimir.Marek@oracle.com>
parents: 878
diff changeset
    25
# Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
878
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    26
#
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    27
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    28
. /lib/svc/share/smf_include.sh
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    29
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    30
SAMBA_CONFIG=/etc/samba/smb.conf
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    31
1140
501d8b6b07c2 15758029 SUNBT7116639 Winbind SMF service should detect its failure
Vladimir Marek <Vladimir.Marek@oracle.com>
parents: 878
diff changeset
    32
# Check if given service is working properly
501d8b6b07c2 15758029 SUNBT7116639 Winbind SMF service should detect its failure
Vladimir Marek <Vladimir.Marek@oracle.com>
parents: 878
diff changeset
    33
check_running() {
501d8b6b07c2 15758029 SUNBT7116639 Winbind SMF service should detect its failure
Vladimir Marek <Vladimir.Marek@oracle.com>
parents: 878
diff changeset
    34
	case "$SMF_FMRI" in
501d8b6b07c2 15758029 SUNBT7116639 Winbind SMF service should detect its failure
Vladimir Marek <Vladimir.Marek@oracle.com>
parents: 878
diff changeset
    35
		svc:/network/winbind:*)
501d8b6b07c2 15758029 SUNBT7116639 Winbind SMF service should detect its failure
Vladimir Marek <Vladimir.Marek@oracle.com>
parents: 878
diff changeset
    36
			# It takes some time before winbind starts to really work
501d8b6b07c2 15758029 SUNBT7116639 Winbind SMF service should detect its failure
Vladimir Marek <Vladimir.Marek@oracle.com>
parents: 878
diff changeset
    37
			# This is infinite loop which will be killed after smf timeout
501d8b6b07c2 15758029 SUNBT7116639 Winbind SMF service should detect its failure
Vladimir Marek <Vladimir.Marek@oracle.com>
parents: 878
diff changeset
    38
			while : ; do
501d8b6b07c2 15758029 SUNBT7116639 Winbind SMF service should detect its failure
Vladimir Marek <Vladimir.Marek@oracle.com>
parents: 878
diff changeset
    39
				sleep 2
501d8b6b07c2 15758029 SUNBT7116639 Winbind SMF service should detect its failure
Vladimir Marek <Vladimir.Marek@oracle.com>
parents: 878
diff changeset
    40
				PING=`/usr/bin/wbinfo --ping-dc 2>&1`
501d8b6b07c2 15758029 SUNBT7116639 Winbind SMF service should detect its failure
Vladimir Marek <Vladimir.Marek@oracle.com>
parents: 878
diff changeset
    41
				if [ $? -eq 0 ]; then
501d8b6b07c2 15758029 SUNBT7116639 Winbind SMF service should detect its failure
Vladimir Marek <Vladimir.Marek@oracle.com>
parents: 878
diff changeset
    42
					break
501d8b6b07c2 15758029 SUNBT7116639 Winbind SMF service should detect its failure
Vladimir Marek <Vladimir.Marek@oracle.com>
parents: 878
diff changeset
    43
				fi
501d8b6b07c2 15758029 SUNBT7116639 Winbind SMF service should detect its failure
Vladimir Marek <Vladimir.Marek@oracle.com>
parents: 878
diff changeset
    44
				echo "$PING"
501d8b6b07c2 15758029 SUNBT7116639 Winbind SMF service should detect its failure
Vladimir Marek <Vladimir.Marek@oracle.com>
parents: 878
diff changeset
    45
			done
501d8b6b07c2 15758029 SUNBT7116639 Winbind SMF service should detect its failure
Vladimir Marek <Vladimir.Marek@oracle.com>
parents: 878
diff changeset
    46
			;;
501d8b6b07c2 15758029 SUNBT7116639 Winbind SMF service should detect its failure
Vladimir Marek <Vladimir.Marek@oracle.com>
parents: 878
diff changeset
    47
	esac
501d8b6b07c2 15758029 SUNBT7116639 Winbind SMF service should detect its failure
Vladimir Marek <Vladimir.Marek@oracle.com>
parents: 878
diff changeset
    48
	return 0
501d8b6b07c2 15758029 SUNBT7116639 Winbind SMF service should detect its failure
Vladimir Marek <Vladimir.Marek@oracle.com>
parents: 878
diff changeset
    49
}
501d8b6b07c2 15758029 SUNBT7116639 Winbind SMF service should detect its failure
Vladimir Marek <Vladimir.Marek@oracle.com>
parents: 878
diff changeset
    50
878
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    51
case "$1" in
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    52
	start)
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    53
		if [ ! -f "$SAMBA_CONFIG" ]; then
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    54
			echo "Configuration file '$SAMBA_CONFIG' does not exist."
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    55
			exit 1
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    56
		fi
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    57
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    58
		# Command to execute is found in second and further script arguments
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    59
		shift
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    60
		eval "[email protected]"
1140
501d8b6b07c2 15758029 SUNBT7116639 Winbind SMF service should detect its failure
Vladimir Marek <Vladimir.Marek@oracle.com>
parents: 878
diff changeset
    61
		check_running
878
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    62
		;;
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    63
	stop)
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    64
		# kill whole contract group
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    65
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    66
		# first send TERM signal and wait 30 seconds
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    67
		smf_kill_contract $2 TERM 1 30
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    68
		ret=$?
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    69
		[ $ret -eq 1 ] && exit 1
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    70
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    71
		# If there are still processes running, KILL them
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    72
		if [ $ret -eq 2 ] ; then
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    73
			smf_kill_contract $2 KILL 1
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    74
		fi
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    75
		;;
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    76
	*)
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    77
		cat <<-EOT
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    78
			Usage:
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    79
			  $0 start <command to run>
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    80
			  $0 stop <contract number to kill>
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    81
		EOT
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    82
		exit 1
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    83
		;;
f5bfc829326f 7144175 samba service enters maintenance mode after SIGKILL
Vladimir Marek <Vladimir.Marek@oracle.com>
parents:
diff changeset
    84
esac