OpenSolaris Solaris Forum  
     

Left Nav FAQ Members List Default Password Members List Linux Commands Search Today's Posts Mark Forums Read Right Nav

Left Container Right Container
 

Go Back   OpenSolaris Solaris Forum Solaris General

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-26-2012, 10:12 AM
Junior Member
 
Join Date: Jun 2012
Posts: 2
Default SMF executes start method more than once. Why?

Hi. I've been struggling with this for some time. I need to have service which will run on zone boot and run only once. For some reason my service is executing start script 3 times. Any ideas why is that happening?

service manifest:
Code:
<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<!--
    Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
    Use is subject to license terms.

    pragma ident        "@(#)registerInDAS.xml 1.2     04/08/09 SMI"
-->

<service_bundle type='manifest' name='OPTnew:registerInDAS'>

<service
    name='site/registerInDAS'
    type='service'
    version='1'>

    <single_instance/>
	<dependency name='fs-local' grouping='require_all' restart_on='none' type='service'>
            <service_fmri value='svc:/system/filesystem/local' />
        </dependency>
        <dependency name='network-service' grouping='require_all' restart_on='none' type='service'>
            <service_fmri value='svc:/network/service' />
        </dependency>

        <exec_method
            type='method'
            name='start'
            exec='/registerInDAS start'  
            timeout_seconds='30' />

        <exec_method
            type='method'
            name='stop'
            exec='/registerInDAS stop'
            timeout_seconds='30' />

        <property_group name='startd' type='framework'>
                <propval name='duration' type='astring' value='transient' />
        </property_group>

        <instance name='default' enabled='true' />

        <stability value='Unstable' />
 
        <template>
                <common_name>
                        <loctext xml:lang='C'>
                                Register In DAS
                        </loctext>
                </common_name>
        </template>
</service>

</service_bundle>
script:
Code:
#!/bin/sh
#
# File: /etc/init.d/registerInDAS
#
# Purpose: Registers virtual machine in glassfish DAS
#

RETVAL=0
DATE=`date`
start() {
    #echo "Registering in glassfish:" #\c
    #$SWIKI_CMD -headless $SWIKI_IMG &
    #RETVAL=$?
    #[ $RETVAL -eq 0 ] && echo "ok" || echo "failed"
    echo "startup $DATE" >> /registerInDASLOG.txt
	
	if [ ! -f /mnt/cust ]; then
	    mkdir -p /mnt/cust
	fi

	umount /mnt/cust
	HOSTNAME=`hostname`
	IMAGE_NAME=$HOSTNAME"cust.iso"
	IMAGE_PATH=/virt/$IMAGE_NAME
	GLASSFISH_HOME=/etc/opt/glassfish3

	ret=`lofiadm $IMAGE_PATH`
	if [ $? -eq 1 ]; then
		echo "lofiadm $IMAGE_PATH returned 1:$ret" >> /registerInDASLOG.txt
	else
		echo "lofiadm $IMAGE_PATH returned 0:$ret" >> /registerInDASLOG.txt
		lofiadm -d $ret
	fi

	mount -F hsfs -o ro `lofiadm -a $IMAGE_PATH` /mnt/cust/
	lofiadm -d /dev/lofi/1
	. /mnt/cust/customization.
	ip_address=`ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2}'`
	
	if [ ! -f /etc/opt/glassfish3/configured_ip ]; then

		touch /etc/opt/glassfish3/configured_ip
    		if [ ! -f /mnt/cust/customization. ]; then
        		echo "image customization not configured" >> /registerInDASLOG.txt
        		exit 1
    		fi

   		echo "my master is $GroupMasterMachine and the port is $GroupMasterPort, my IP is $ip_address" >> /registerInDASLOG.txt
    		
    		vmName=`echo $Group_$Machine_$MachineAlias`

			if [ -z $AuthToken ]; then
				echo "No authentication token provided in the customization file" >> /registerInDASLOG.txt
				exit 1
			else
				if [ -f /mnt/cust/id_dsa.pub ]; then
					echo "Installing public key" >> /registerInDASLOG.txt
						if [ ! -f /.ssh ]; then
							mkdir /.ssh
						fi
						cat /mnt/cust/id_dsa.pub | tee -a /.ssh/authorized_keys2 >/dev/null
				fi

				if [ -f /mnt/cust/id_rsa.pub ]; then
						echo "Installing public key" >> /registerInDASLOG.txt
						if [ ! -f /.ssh ]; then
							mkdir /.ssh
						fi
						cat /mnt/cust/id_rsa.pub | tee -a /.ssh/authorized_keys2 >/dev/null
				fi

				echo "$DASAddress   $DAS    # added by glassfish" >> /etc/hosts
				echo "$ip_address   $HOSTNAME    # added by glassfish" >> /etc/hosts

				echo "$GLASSFISH_HOME/bin/asadmin -H $GroupMasterMachine -p $GroupMasterPort --passwordfile $GLASSFISH_HOME/bin/passwords.txt --_authtoken $AuthToken register-virtual-machine --group $Group --machine $Machine --address $ip_address --sshuser root --installdir $GLASSFISH_HOME --cluster $Cluster $MachineAlias" >> /registerInDASLOG.txt
				$GLASSFISH_HOME/bin/asadmin -H $GroupMasterMachine -p $GroupMasterPort --passwordfile $GLASSFISH_HOME/bin/passwords.txt --_authtoken $AuthToken register-virtual-machine --group $Group --machine $Machine --address $ip_address --sshuser root --installdir $GLASSFISH_HOME --cluster $Cluster $MachineAlias
				RETVAL=$?
				echo -e "register-virtual-machine: $RETVAL\n" >> /registerInDASLOG.txt
				if [ $RETVAL -eq 0 ]; then
						echo "$ip_address" > /etc/opt/glassfish3/configured_ip
				else
						echo "Asadmin register instance returned $RETVAL" >> /registerInDASLOG.txt
				fi
			fi
	else
		configured_ip_address=`cat /etc/opt/glassfish3/configured_ip`
    		nodeName=`echo $Group"_"$Machine"_"$MachineAlias`

    		echo "Comparing $ip_address and $configured_ip_address" >> /registerInDASLOG.txt
    		if [ $ip_address != $configured_ip_address ]; then
			echo "$GLASSFISH_HOME/glassfish/bin/asadmin -H $GroupMasterMachine -p $GroupMasterPort --passwordfile $GLASSFISH_HOME/bin/passwords.txt --_authtoken $AuthToken update-node-ssh --nodehost $ip_address $nodeName"
			$GLASSFISH_HOME/glassfish/bin/asadmin -H $GroupMasterMachine -p $GroupMasterPort --passwordfile $GLASSFISH_HOME/bin/passwords.txt --_authtoken $AuthToken update-node-ssh --nodehost $ip_address $nodeName
        		if [ $? -eq 0 ]; then
            			echo "$ip_address" > /etc/opt/glassfish3/configured_ip
            			sync
        		fi
    		fi

    		# notify the vm is up.
    		echo "$GLASSFISH_HOME/glassfish/bin/asadmin -H $GroupMasterMachine -p $GroupMasterPort --passwordfile $GLASSFISH_HOME/bin/passwords.txt --_authtoken $AuthToken2 register-startup --group $Group --machine $Machine --address $ip_address --cluster $Cluster $nodeName" >> /registerInDASLOG.txt
    		$GLASSFISH_HOME/glassfish/bin/asadmin -H $GroupMasterMachine -p $GroupMasterPort --passwordfile $GLASSFISH_HOME/bin/passwords.txt --_authtoken $AuthToken2 register-startup --group $Group --machine $Machine --address $ip_address --cluster $Cluster $nodeName
	fi

	return $RETVAL
}
 
stop() {
    #echo "Unregister in glassfish" #\c
    #SQUEAK_PID=`ps -ef |grep $SQUEAK_CMD |grep -v grep |awk '{print $2}'`
    #kill $SQUEAK_PID
    #RETVAL=$?
    #[ $RETVAL -eq 0 ] && echo "ok" || echo "failed"
    #rm /heh.txt
    return $RETVAL
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
esac

exit $RETVAL
thank you for all your suggestions,
Peter
Reply With Quote
Sponsored Links

  #2 (permalink)  
Old 06-26-2012, 10:35 AM
Junior Member
 
Join Date: Jun 2012
Posts: 2
Default

ok. Guess I found it. SMF was trying to start service, but service couldn't be online because there was a little bug in a script, so it attempted to start it 3 times. I was redirecting echo stream to non existing file... eh
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
start off with installer package idella Solaris General 4 07-16-2010 07:20 AM
How can I start and Stop services in Solaris Solaris Services OpenSolaris Security 1 09-12-2009 09:36 PM
Create a service at start up Spax Solaris Networking 0 04-01-2009 03:01 PM


All times are GMT. The time now is 12:26 AM.


Powered by vBulletin. Copyright 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.