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.
#!/bin/sh
# onscheduler: turn the java when it is off
# variables:
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 >> $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
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment