Hi Vamsee,

Note, the current version of STAF is V3.4.8 (not 3.4.1) so you may want to 
upgrade to take advantage of the latest bug fixes and new features.

Your init script needs to source STAFEnv.sh (located in the directory 
where you installed STAF, e.g. /usr/local/staf) to set the environment 
variables needed by STAF before starting STAFProc.  Also, pass the 
STAF_INSTANCE_NAME to STAFEnv.sh (generally this should be STAF).  When 
you start STAFProc, you should redirect its output to a file (e.g. 
/usr/local/staf/STAFProc.out) as this output shows if STAFProc was 
initialized or if an error occurred (so you can check this file if you 
encounter a problem).  For example:

. /usr/local/staf/STAFEnv.sh STAF
STAFProc >> /usr/local/staf/STAFProc.out &

Note that you should test out your init script manually.  For example:

/etc/rc.d/stafproc start

Here is a sample init script that you can use to start STAFProc upon 
boot-up on FreeBSD and to shutdown STAFProc when the system shuts down. 
Cut and paste its content into a file named "stafproc" and put this file 
in the /etc/rc.d directory.  Give this "stafproc" file execution 
permissions (e.g. chmod +u+x stafproc).

#!/bin/sh
#
# PROVIDE: stafproc
# REQUIRE: networking filesystems
# KEYWORD: shutdown
#
# Add the following line to /etc/rc.conf to enable STAFProc
#
# stafproc_enable="YES"
#

. /etc/rc.subr

name="stafproc"
start_cmd="stafproc_start"
stop_cmd="stafproc_stop"
stafproc_enable="yes"
rcvars=stafproc_enable

STAF_HOME=/usr/local/staf
STAF_INSTANCE_NAME=STAF

# Include any directories you want in STAFProc's PATH
PATH=/usr/local/jdk1.5.0/bin:$PATH
export PATH

stafproc_start()
{
    echo "Starting STAFProc..."
    . $STAF_HOME/STAFEnv.sh $STAF_INSTANCE_NAME

    # Check if STAFProc is already running
    STAF local PING PING > /dev/null
    if [ $? -eq 0 ]; then
        echo "STAFProc is already running with 
STAF_INSTANCE_NAME=$STAF_INSTANCE_NAME"
        return 0
    fi

    STAFProc >> $STAF_HOME/STAFProc.out &
    RETVAL=$?

    echo "STAFProc output will be written to /usr/local/staf/STAFProc.out"

    if [ $RETVAL -eq 0 ]; then
        echo "Waiting for STAFProc to finish initalizing..."
        # Ping every 2s (up to 30 attempts) until returns RC 0
        count=1
        while [ $count -le 30 ]; do
            sleep 2
            STAF local PING PING > /dev/null
            RETVAL=$?
            if [ $RETVAL -eq 0 ]; then
                echo "STAFProc initialized"
                count=30
            fi
            count=$(($count+1))
        done
    fi

    echo
    return $RETVAL
}

stafproc_stop()
{
    echo "Shutting down STAFProc..."

    # Shutdown STAF (stops any STAF services and STAFProc)
    . $STAF_HOME/STAFEnv.sh $STAF_INSTANCE_NAME
    STAF local SHUTDOWN SHUTDOWN
    RETVAL=$?
    if [ $RETVAL -eq 0 ]; then
        echo "Waiting for STAFProc to finish shutdown..."
        # Ping every 2s (up to 60 attempts) until get RC 21
        # which means "STAF not running"
        count=1
        while [ $count -le 60 ]; do
            sleep 2
            STAF local PING PING > /dev/null
            RETVAL=$?
            if [ $RETVAL -eq 21 ]; then
                echo "STAFProc ended normally"
                RETVAL=0
                count=60
            fi
            count=$(($count+1))
        done
    elif [ $RETVAL -eq 21 ]; then
        echo "STAFProc is not currently running so shutdown is ignored"
    fi

    echo
    return $RETVAL
}

load_rc_config $name
run_rc_command "$1"


Init Script Customization Notes:

1) If you installed STAF to a different location than /usr/local/staf then 
change the STAF_HOME variable. 

2) This init script adds a Java bin directory to the PATH environment 
variable as follows so that if STAFProc registers any Java services it can 
find the java executable without specifying the JVM option.  Customize 
this for the the location of your JVM (or any other directories you want 
to have in STAFProc's PATH) or remove these lines if you don't need to 
change the PATH.

# Include any directories you want in STAFProc's PATH
PATH=/usr/local/jdk1.5.0/bin:$PATH
export PATH


Make sure to test that the stafproc init script is working correctly by 
attempting to stop and start and restart STAFProc as follows:

# /etc/rc.d/stafproc stop
Shutting down STAFProc...
Response
--------

Waiting for STAFProc to finish shutdown...
STAFProc ended normally

# /etc/rc.d/stafproc start
Starting STAFProc...
STAFProc output will be written to /usr/local/staf/STAFProc.out
Waiting for STAFProc to finish initalizing...
STAFProc initialized

# /etc/rc.d/stafproc restart
Shutting down STAFProc...
Response
--------

Waiting for STAFProc to finish shutdown...
STAFProc ended normally

Starting STAFProc...
STAFProc output will be written to /usr/local/staf/STAFProc.out
Waiting for STAFProc to finish initalizing...
STAFProc initialized

#

Finally, edit file /etc/rc.conf and add the following line to enable the 
stafproc service:

stafproc_enable="YES"

Now try rebooting the system to verify that it is shutting down and 
starting STAFProc when the system is rebooted.

I plan on adding these instructions for FreeBSD to section "11. Starting 
STAFProc during system reboot" in the STAF Installation Guide at 
http://staf.sourceforge.net/current/STAFInstall.pdf.

--------------------------------------------------------------
Sharon Lucas
IBM Austin,   luc...@us.ibm.com
(512) 286-7313 or Tieline 363-7313




From:   arya vamsee <vamsee...@gmail.com>
To:     staf-users@lists.sourceforge.net, 
Date:   02/28/2012 12:26 PM
Subject:        [staf-users] start STAF on Free BSD after reboot



Hi All,

I am a new user of STAF.
I have installed STAF on FreeBSD 7.4 .

My requirement is to start the STAF Process after boot process.

I am able to start STAF process manually. Below is the output after 
starting the process manually:
bsd72# /usr/local/staf/bin/STAFProc

Machine          : bsd72
Machine nickname : bsd72
Startup time     : 20120229-04:38:20

STAFProc version 3.4.1 initialized


I have placed a script in the following location, to start  STAF process 
automatically after bootup, but it is not working.
location :  /etc/rc.d/      ( path )

==============================================
Script name : staf
Script content : 

#!/bin/sh
# PROVIDE: staf
# REQUIRE: dhclient sshd hostapd securelevel
# KEYWORD: shutdown

. /etc/rc.subr

name="staf"
rcvar=`set_rcvar`
force_depend dhclient

staf_bsd_start()
{
        echo "Starting the STAF Process"
        ( /usr/local/staf/bin/STAFProc  & )
        echo "Started the STAF Proces...."
}
: ${set_rcvar:="YES"}

command="/usr/local/staf/bin/STAFProc &"
load_rc_config $name
run_rc_command "$1"

==============================================

/var/log/messages shows following messages related to staf script ( which 
was kept to run at boot time )

Feb 28 04:30:46 bsd72 root: /etc/rc: DEBUG: checkyesno: staf_enable is set 
to YES.
Feb 28 04:30:46 bsd72 root: /etc/rc: DEBUG: run_rc_command: doit: 
/usr/local/staf/bin/STAFProc &

but it throws the following error, when I try to check if staf has started

bsd72# staf bsd72 ping ping
Error registering with STAF, RC: 21


Is there a log file related to STAF, to check what is the error and why it 
is not able to start the STAF process after reboot
Please let me know, if there is a solution for this issue.

Thanks,
Vamsee
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users

Reply via email to