Score:0

How to execute a ConnectAll Application restart script using a cron Job

cn flag

Could you please guide me with the following,

Adding the ConnectAll Application restart script for reference:

#!/bin/sh -e
# JIRA startup script
#chkconfig: 2345 80 05
#description: JIRA

# Define some variables
# Name of app ( JIRA, Confluence, etc )
APP=connectall
APP1=Mule
# Name of the user to run as
USER=root
# Location of application's bin directory
BASE=/mulesoft/connectall/CATomcat/bin
#BASEMule=/mulesoft/connectall/mulesoft/mule-standalone-3.9.0
# Location of Java JDK
export JAVA_HOME=/usr/jdk1.8.0_171


case "$1" in

 # Stop command
  stop)
    #echo "Stopping $APP"
    #/bin/su -m $USER -c "$BASE/shutdown.sh &> /dev/null"
    #echo "$APP stopped successfully"


    echo "Stopping $APP1"
    /bin/su -m $USER -c "/mulesoft/connectall/mulesoft/mule-standalone-3.9.0/bin/mule stop &> /dev/null"
    echo "$APP1 stopped successfully"

    echo "Stopping $APP"
    /bin/su -m $USER -c "$BASE/shutdown.sh &> /dev/null"
    echo "$APP stopped successfully"
    ;;

  # Start command
  start)
    echo "Starting $APP"
    /bin/su -m $USER -c "$BASE/startup.sh &> /dev/null"
    echo "$APP started successfully"

     echo "Starting $APP1"
    /bin/su -m $USER -c "/mulesoft/connectall/mulesoft/mule-standalone-3.9.0/bin/mule start &> /dev/null"
    echo "$APP1 started successfully"

    ;;
  # Stop command
 # stop)
  #  echo "Stopping $APP"
   # /bin/su -m $USER -c "$BASE/bin/shutdown.sh &> /dev/null"
    #echo "$APP stopped successfully"
    #;;
   #Restart command
   restart)
        $0 stop
        sleep 60
        $0 start
        ;;
  *)
 echo "Usage: /etc/init.d/$APP restart}"
  exit 1
   ;;
esac

The above script is in the name connectall-auto-restart in the location /mulesoft (this is an external mount). So when I execute the script manually from the location /mulesoft using ./connectall-auto-restart restart the application restarts fine.

However when I configure the same in a cron job like below

30 08 1-7 * 6 /mulesoft/connectall-auto-restart
30 08 17-23 * 6 /mulesoft/connectall-auto-restart

the cron runs exactly at the time but the cron does not initiate the script. (Meaning the cron triggers the job but my application is not restarting).

root@balqmu101:/var/log# cat syslog | grep connectall-auto-restart
Sep 18 08:30:01 balqmu101 CRON[3232401]: (root) CMD (/mulesoft/connectall-auto-restart)

I have also tried the following and that also is not working.

30 08 1-7 * 6 /mulesoft/connectall-auto-restart restart
30 08 17-23 * 6 /mulesoft/connectall-auto-restart restart

Regards Aravind Viswanathan

Score:0
it flag

Jobs run through cron, or systemd startup scripts aren't run in the same runtime environment that you have on your desktop. systemd startup scripts are run as root. None of your PATH changes, or other environment variable settings from ~/.bashrc are automatically propagated to your cron job. For example, there's no $DISPLAY, so GUI programs need special treatment (read man xhost).

One can set environment variables for all one's cron jobs in the crontab file Read man 5 crontab.

Look at the results of echo "=== id ===";id;echo "=== set ===";set;echo "=== env ===";env | sort;echo "=== alias ===";alias in each of your environments.

Since the command part of the crontab line is, by default, interpreted by /bin/sh, which has a simpler syntax than /bin/bash, I recommend having command be a call to a bash script (executable, mounted, starts with #!/bin/bash) which sets up the environment, then calls the desired program.

Aravind Viswanathan avatar
cn flag
Hi Waltinator, You are a Genius. Yes your suggestion worked. Thanks a lot.
waltinator avatar
it flag
Please click the checkmark to "accept" my answer, if it helped you, and might help others.
Aravind Viswanathan avatar
cn flag
where is the "accept" on this screen?
waltinator avatar
it flag
Click the checkmark.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.