Ad Widget

Collapse

Java Gateway autorun init script?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xpehbam
    Junior Member
    • Jul 2012
    • 17

    #1

    Java Gateway autorun init script?

    Hello,

    I am evaluating the virtual appliance 2.0 and am looking to write a script to auto start the java gateway when the server starts. I know the settings.sh already allows the gateway to run as a background process, but it's surprising that service functionality is not included from the start. Has anyone already accomplished this? Is there something to look out for?
  • kelbergs
    Junior Member
    • Jul 2012
    • 5

    #2
    You should have probably specified your OS flavour here.

    Here is the init script for RedHat/CentOS. Stuff between <<>> is what you need to change according to your setup.

    # We need java
    export PATH=$PATH:/apps/java/jdk-1.6/bin/

    # zabbix details
    ZABBIX_JAVAGW_START=<<Insert path here>>/startup.sh
    ZABBIX_JAVAGW_STOP=<<Insert path here>>/shutdown.sh
    PIDFILE=<<Insert path here to hold pid here>>/zabbix_java.pid

    # Source function library.
    . /etc/rc.d/init.d/functions

    # Source networking configuration.
    . /etc/sysconfig/network

    # Check that networking is up.
    [ ${NETWORKING} = "no" ] && exit 0

    [ -x $ZABBIX_AGENTD ] || exit 5

    RETVAL=0

    case "$1" in
    start)
    echo -n "Starting zabbix java gateway: "
    daemon $ZABBIX_JAVAGW_START
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/zabbix-java
    ;;
    stop)
    echo -n "Shutting down zabbix agent: "
    $ZABBIX_JAVAGW_STOP
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/zabbix-java
    ;;
    restart|reload)
    $0 stop
    $0 start
    RETVAL=$?
    ;;
    *)
    echo "Usage: $0 {start|stop|restart|reload}"
    exit 1
    ;;
    esac

    exit $RETVAL

    Comment

    • kelbergs
      Junior Member
      • Jul 2012
      • 5

      #3
      Forgot to mention, you also need to do this:

      chmod 755 /etc/init.d/zabbix_java_gateway #or any name you like
      chkconfig --add zabbix_java_gateway
      chkconfig zabbix_java_gateway on
      Again, chkconfig is a RedHat specific thing.

      Comment

      • xpehbam
        Junior Member
        • Jul 2012
        • 17

        #4
        Thank you for the response kelberg. The virtual appliance I am using runs OpenSUSE 12.1, so I don't believe that script will work. I am planning on following the skeleton file init script.

        Comment

        • nnoori
          Junior Member
          • Nov 2012
          • 6

          #5
          Zabbix Java Gateway start/stop script

          thanks kelbergs for the script.. I just used it on Ubuntu to start|stop the java gateway .. I had to tweak it a bit to get it to work and now it works fine...

          Here is the Ubuntu addition

          Code:
          #/bin/sh
          #Zabbix Java gateway start/stop script.
          
          #Check for Java - 
          #nnoori: I already set my JAVA_HOME in ".profile" so I deleted that line
          #        In my case I use OpenJDK6 for Ubuntu 12.04
          #export PATH=$PATH:<<JAVA_HOME>>/bin/
          
          # zabbix details
          ZABBIX_JAVAGW_START=/usr/local/sbin/zabbix_java/startup.sh
          ZABBIX_JAVAGW_STOP=/usr/local/sbin/zabbix_java/shutdown.sh
          PID=/tmp/zabbix_java.pid
          
          test -f $ZABBIX_JAVAGW_START || exit 0 
          
          
          RETVAL=0
          
          case "$1" in
          start)
          echo -n "Starting zabbix java gateway: "
          	$ZABBIX_JAVAGW_START
          	
          RETVAL=$?
          echo
          [ $RETVAL -eq 0 ] && touch /var/lock/subsys/zabbix-java
          ;;
          stop)
          echo -n "Shutting down zabbix agent: "
          	$ZABBIX_JAVAGW_STOP
          
          RETVAL=$?
          echo
          [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/zabbix-java
          ;;
          restart|reload)
          $0 stop
          $0 start
          RETVAL=$?
          ;;
          *)
          echo "Usage: $0 {start|stop|restart|reload}"
          exit 1
          ;;
          esac
          
          exit $RETVAL
          • Put the file in /etc/init.d
          • Update permission for script file
            Code:
            #sudo chmod 755 /etc/init.d/<<script_file_name>>
          • If you want to set Zabbix to start when the machine boots then execute
            Code:
            sudo update-rc.d zabbix-java defaults


          Now we are good to go!

          I used also the instructions from this Zabbix wiki page http://www.zabbix.com/wiki/howto/ins.../ubuntuinstall

          Nadia
          Last edited by nnoori; 06-12-2012, 21:56.

          Comment

          Working...