Cron job runs on both master and mirror server, why?

Discussion in 'Installation/Configuration' started by snowfly, Jul 25, 2011.

  1. snowfly

    snowfly Member

    I have 2 web servers running ISPconfig 3, first server is master, and second is set to be "Is mirror of Server" master.

    When creating cron jobs on the master server using ISPConfig, it appears these cron jobs are replicated across on the mirror.
    Hence our crons are run twice.

    e.g. I have a cron to hit a PHP script (URL cron), and the PHP script sends me an email.
    I get the email twice, because both the master and mirror server run the cron.

    How do I get the mirror server to not run crons?
    I only use the mirror server as a backup, and ISPConfig mirrors all the config, and I use rsync to mirror data.
     
  2. CSsab

    CSsab New Member

    No cron on mirror

    Hi Snowfly,

    The cron jobs give up-to-date information about whats happening on the mirror so IMO it's not a good idea not to have the cron jobs running.

    Maybe there is something you could do with your email script which prevents the mirror from sending you mail.

    If you still want to edit the cron jobs you can do this:

    As root on the mirror

    crontab -e

    select your editor (<----- most likely "vim")

    and you should see these 2 jobs:

    * * * * * /usr/local/ispconfig/server/server.sh > /dev/null 2>> /var/log/ispconfig/cron.log
    30 00 * * * /usr/local/ispconfig/server/cron_daily.sh > /dev/null 2>> /var/log/ispconfig/cron.log


    You can comment them # to stop them from running.
     
  3. snowfly

    snowfly Member

    Hi CSsab,

    No I do not mean the ISPConfig cron script.
    I am talking about user/client cron scripts.

    These are listed under /etc/cron.d/

    For example, on my master server I have:
    /etc/cron.d/ispc_web26

    And on my mirror server I also have:
    /etc/cron.d/ispc_web26

    And both contain the same (where URL is my PHP script):
    */5 * * * * web26 /usr/bin/wget -q -O /dev/null '<URL>' >/dev/null 2>&1


    So the PHP script gets run twice, and I get to emails sent to me, because at the bottom of the PHP script I put a php mail(...) command.

    So wanting to know a way to stop user/client cron jobs getting replicated and run on the mirror server.
     
  4. CSsab

    CSsab New Member

    You can exclude a file, files and an entire directory using the:

    $ rsync -avz --exclude

    command.

    So you could either exclude anything in etc/cron.d/
    or the entire directory etc/cron.d from being backed up on the mirror.

    Did you use a guide to set up rsync? If so which one?
     
    Last edited: Jul 25, 2011
  5. snowfly

    snowfly Member

    Sorry you still misunderstand my problem.
    This has nothing to do with rsync.

    This is to do with internal ISPConfig functionality.

    In ISPConfig I have configured my backup server to Mirror the master server.
    This is done under: System > Server Services > {click on backup server} > Select option "Is mirror of Server" > {select master server from drop down box}

    With this setting, every action I submit on my ISPConfig control panel for the master server, is replicated / mirrored on the backup server.

    e.g.
    - I create a web domain on master server, web domain settings (not content) is mirrored on backup server
    - I create an FTP user on master server, FTP user is mirrored on backup server

    And when I create a client cron job on the master server (Under Sites > Cron Jobs > Add new Cron Job)
    This cron job is replicated on the backup server.

    ISPConfig itself creates the cron job on the master server at:
    /etc/cron.d/ispc_web26

    And ISPConfig on the backup server creates the cron job on the backup server:
    /etc/cron.d/ispc_web26

    Make sense?
     
  6. CSsab

    CSsab New Member

    Yes I understand what you mean - sorry about the confusion.

    I only use the mirror function for DNS - that is to say, my ns2 is a mirror of ns1 and those two are not used for anything else.

    I would use rsync to back up everything else.

    Have you tried doing something like this:

    On the slave as root:

    cp /etc/cron.d/ispc_web26 /etc/cron.d/ispc_web26.ORIG
    rm /etc/cron.d/ispc_web26
    vi /etc/cron.d/ispc_web26


    ## put something here... save and close file

    chmod -x /etc/cron.d/ispc_web26

    The mirror function on the master may not be able to overwrite the file then.

    But maybe there would be errors.
     
  7. snowfly

    snowfly Member

    That wouldn't work, as its only stopping one specific cron, not multiple crons.

    Any cron I setup on master is also setup on backup (mirror)
    So every cron is run twice.

    Must be a way to stop this?
     
  8. mattltm

    mattltm Member

    Did this ever get resolved?

    I am having a nightmare with duplicate cron entries!
     

Share This Page