1

I have a jar file which I am running like this in my Ubuntu 10.10 and then it starts my exhibitor server in the background -

nohup java \
    -jar /pekooz/exhibitor-1.5.1/lib/exhibitor-1.5.1-jar-with-dependencies.jar \
    -c file --fsconfigdir /opt/exhibitor/conf \
    --hostname machineA > exhibitor.out &

Now I am trying to use crontab to check whether my exhibitor server is running or not. If it is not running, then start it again so I decided to use crontab and I did the below steps to setup crontab -

  1. Created a new crontab by running crontab -e.
  2. Added this line to the file that just opened

    */5 * * * * pgrep -f exhibitor || nohup java -jar /pekooz/exhibitor-1.5.1/lib/exhibitor-1.5.1-jar-with-dependencies.jar -c file --fsconfigdir /opt/exhibitor/conf --hostname machineA > exhibitor.out
    
  3. Save the file and exit the editor.

So for the testing purpose to see whether my crontab is working or not, I started my exhibitor server like this firstly -

$ nohup java \
    -jar ./exhibitor-1.5.1/lib/exhibitor-1.5.1-jar-with-dependencies.jar \
    -c file --fsconfigdir /opt/exhibitor/conf \
    --hostname machineA > exhibitor.out &
[1] 14401

$ nohup: ignoring input and redirecting stderr to stdout

And then I setup my crontab as shown above with the steps. After that I did kill -9 14401 so that I can see whether my exhibitor server is getting restarted automatically by crontab or not. And apparently, they didn't get started up and I don't see any error as well. Below is the log -

$ sudo tail -f /var/log/syslog
Nov  5 17:21:45 machineA crontab[12755]: (cronusapp) BEGIN EDIT (cronusapp)
Nov  5 17:23:17 machineA crontab[12755]: (cronusapp) END EDIT (cronusapp)
Nov  5 17:25:01 machineA CRON[13671]: (root) CMD (  puppet apply /etc/puppet/manifests/motd-stats.pp >>$PUPPET_LOG 2>&1)
Nov  5 17:25:01 machineA CRON[13672]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Nov  5 17:25:01 machineA CRON[13673]: (cronusapp) CMD (pgrep -f exhibitor || nohup java -jar /pekooz/exhibitor-1.5.1/lib/exhibitor-1.5.1-jar-with-dependencies.jar -c file --fsconfigdir /opt/exhibitor/conf --hostname machineA > exhibitor.out)
Nov  5 17:25:01 machineA postfix/pickup[2345]: 2B0D8819F9: uid=78402 from=<cronusapp>
Nov  5 17:25:01 machineA postfix/cleanup[13679]: 2B0D8819F9: message-id=<20141106002501.2B0D8819F9@machineA.domain.host.com>
Nov  5 17:25:01 machineA postfix/qmgr[25623]: 2B0D8819F9: from=<cronusapp@machineA.domain.host.com>, size=814, nrcpt=1 (queue active)
Nov  5 17:25:01 machineA postfix/local[13681]: 2B0D8819F9: to=<cronusapp@machineA.domain.host.com>, orig_to=<cronusapp>, relay=local, delay=0.11, delays=0.07/0/0/0.04, dsn=2.0.0, status=sent (delivered to mailbox)
Nov  5 17:25:01 machineA postfix/qmgr[25623]: 2B0D8819F9: removed

What am I doing wrong here? Why my crontab is not working? I just need to restart my exhibitor server automatically if they went down somehow.

  • 2
    You might want to look into using upstart to launch your process: you can tell upstart to "respawn" your program if it dies. – glenn jackman Nov 6 '14 at 0:47
  • @glennjackman I am running Ubuntu 10.10 which has no support whatsoever. I have already tried and some of the commands doesn't work. – arsenal Nov 6 '14 at 3:03
  • 1
    Then perhaps a simple wrapper: sh -c 'while true; do java -jar ...; done' – Patrick Nov 6 '14 at 4:24
  • @Patrick I was not able to understand what you said? :( – arsenal Nov 6 '14 at 4:42
  • He's saying that whatever you're using to run the exhibitor app, wrap it in a while true block. sh -c 'while true; do java -jar ...; done'. This will act like a guard which will constantly keep restarting exhibitor every time it dies. – slm Nov 6 '14 at 4:45
0

Is java in /usr/bin directory? The crontab has a minimal PATH by default. You may have to set JAVA_HOME and PATH in your crontab:

*/5 * * * * JAVA_HOME=/opt/java/latest;export JAVA_HOME; \
    PATH=$PATH:$JAVA_HOME/bin; \
    pgrep -f exhibitor || nohup java \
    -jar /pekooz/exhibitor-1.5.1/lib/exhibitor-1.5.1-jar-with-dependencies.jar \
    -c file --fsconfigdir /opt/exhibitor/conf --hostname machineA > exhibitor.out
  • Yes java is in /usr/bin. This is what I got /usr/bin/java after I did which java. And what is this /opt/java/latest in your suggestion. – arsenal Nov 6 '14 at 3:20
  • Some bizarre installations put java in strange places. Not familiar with Ubuntu, so that was partially a shot in the dark. – Mark Stewart Nov 6 '14 at 4:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.