1752584 Members
4318 Online
108788 Solutions
New Discussion юеВ

Re: MC/SG and cron jobs

 
SOLVED
Go to solution
Gary Hines
Advisor

MC/SG and cron jobs

Hi,
We're running a two-node cluster, and I would like to fail over the cron jobs that should be running on the primary node when it fails. So far the best that I've been able to come up with it to copy the crontab for the operator user to a different name on the backup server, and then change the name in the cluster script, followed by the crontab command to kick it off. The question that now occurs to me is "Isn't the cron now assigned to root?". Anybody else trying to do the same thing or know of a clean way to handle this? Thanks for any help.
9 REPLIES 9
Hai Nguyen_1
Honored Contributor

Re: MC/SG and cron jobs

Gary,

I got a two-node cluster as well. I did it differently. I have the same cron jobs running on both nodes, but they carry out tasks only on the node where the packages are running. All you need to do is build some if-statements into your crons.

Hai
Tom Danzig
Honored Contributor
Solution

Re: MC/SG and cron jobs

In the package script under customer_defined_run_cmds, we do something like:

su oracle -c "crontab /u01/app/oracle/oracle"

where the file /u01/app/oracle/oracle contains the package specific cronjobs.


Additionally, in the package script under customer_defined_halt_cmds, we do:

> /tmp/nothing
su oracle -c "crontab /tmp/nothing"


You can modify the user to be whomever. USe the above as a guide.
Ashwani Kashyap
Honored Contributor

Re: MC/SG and cron jobs

Build a script and put in the cron of both nodes which checks that if "PACKAGE_NAME" is running on "HOSTNAME" . If yes then execute the script, if not then exit out .
Patrick Chim
Trusted Contributor

Re: MC/SG and cron jobs

Hi,

You can bring up the cronjob of other user by root

i.e. su - -c 'crontab '

If you need to remove the cronjob of other user by root, you can type

crontab -r

Just make this statments in a startup and shutdown script and include them in the MC/SG package configuration file and it's OK
(/etc/cmcluster//

Regards,
Patrick
Elif Gius
Valued Contributor

Re: MC/SG and cron jobs

Hi,

Write a script for your crontab, that checks whether the package is running on the localhost. If this is true execute the cronjob, if not exit.
Look at the attachment.

Bye
Elif
Johan Bergwitz
Advisor

Re: MC/SG and cron jobs

You can make a test in the crontab-file, such as 'test -d && ' and then have the same crontabfile on both machines. The command will only execute if the catalog that is mounted by the package exists. Then you don't have to make the test in the actual scripts.

Rgds
Johan
Sebastien Masson
Valued Contributor

Re: MC/SG and cron jobs

Hi,

Create a crontab section in a seperate file, put the file on all machine in your cluster and then add a script line to add the section at package startup and remove the section at package stop. Here some example:

Crontab section in seperate file:
=======================
##BEGIN:mysec
00 7 * * 1,2,3,4,5 /zaza.sh
##END:mysec
=======================
Here a line to remove this section from crontab:
=======================
crontab -l | /sbin/awk 'BEGIN { flag = 0 }{ if (($1 ~ /^##BEGIN:mysec/) && (flag == 0)) { flag = 1; }; if (flag != 1) { print; }; if
(($1 ~ /^##END:mysec/) && (flag == 1)) { flag = 0; } }' | crontab
=======================
Here a three lines to add the section in the crontab:
=======================
crontab -l > /tmp/crontab.zz.new
cat /tmp/crontab.zz.new mycron.sec | crontab
rm -f /tmp/crontab.zz.new
=======================
(mycron.sec is the crontab section).
Mark van Hassel
Respected Contributor

Re: MC/SG and cron jobs

Hi,

The 2 recommendations have some issues: one crontab on each system where you do check package before ecxecuting the crontab entry means that you have to maintain two crontabs and they have to be the same.

When the crontab is activated during package start you can run into problems when the system crashes -> package fails over and crontab is started on standby host -> primary systems boots and start crontab -> result is that you have the same crontab runing on both systems.
What you can do about this is to add a script to the boot sequence that removes the crontab for the user involved. Also add a crontab -r to the stop script of the package in case of manual fail over.
This means that only one crontab is active on one machine at any time.

HtH,

Mark

The surest sign that life exists elsewhere in the universe is that none of it has tried to contact us
Gary Hines
Advisor

Re: MC/SG and cron jobs

Thanks for all for the help. I had totally forgotten about the su option to change the user. That's what I needed, but I'm glad for the feedback about removing the crontab, and finding out which computer the package is running on. I plan to incorporate that into the scripts also. Thanks again for all the help!! :D