Skip to content

Instantly share code, notes, and snippets.

@apsamuel
Last active December 13, 2015 17:09
Show Gist options
  • Select an option

  • Save apsamuel/4945794 to your computer and use it in GitHub Desktop.

Select an option

Save apsamuel/4945794 to your computer and use it in GitHub Desktop.

Revisions

  1. apsamuel revised this gist Feb 13, 2013. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions onsceduler_example.sh
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,14 @@
    #!/bin/sh
    # onscheduler: turn the java when it is off
    # variables:
    savingcell="/root/bet/schedulerLog" #log path
    savingcell="/root/bet/schedulerLog" #log path for scheduler
    applog="/root/bet/application.log"
    pid=$(pgrep -f '.*java.*bet.*Main.*' >/dev/null) #find pid.
    ret=$? #log result 0 - found, 1 - not found

    if [ $ret -ne 0 ]
    then #java is off
    /usr/bin/nohup java -Xmx512m -cp "/root/bet/lib/*:/root/bet/src/" Main >> $savingcell 2>&1 #turn it on with messages redirected to log.
    /usr/bin/nohup java -Xmx512m -cp "/root/bet/lib/*:/root/bet/src/" Main >> $applog 2>&1 #turn it on with messages redirected to log.
    [ $(pgrep -f '.*java.*bet.*Main.*' |wc -l) -eq 1 ] && echo "Started by script on : $(date)" >> $savingcell || echo "Something bad happend, return code: $?" >> $savingcell
    else #java is on
    echo "was already on on : $(date)" >> $savingcell
  2. apsamuel created this gist Feb 13, 2013.
    14 changes: 14 additions & 0 deletions onsceduler_example.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    #!/bin/sh
    # onscheduler: turn the java when it is off
    # variables:
    savingcell="/root/bet/schedulerLog" #log path
    pid=$(pgrep -f '.*java.*bet.*Main.*' >/dev/null) #find pid.
    ret=$? #log result 0 - found, 1 - not found

    if [ $ret -ne 0 ]
    then #java is off
    /usr/bin/nohup java -Xmx512m -cp "/root/bet/lib/*:/root/bet/src/" Main >> $savingcell 2>&1 #turn it on with messages redirected to log.
    [ $(pgrep -f '.*java.*bet.*Main.*' |wc -l) -eq 1 ] && echo "Started by script on : $(date)" >> $savingcell || echo "Something bad happend, return code: $?" >> $savingcell
    else #java is on
    echo "was already on on : $(date)" >> $savingcell
    fi