Cron job seems to run on both master and mirror server

Discussion in 'ISPConfig 3 Priority Support' started by millpark10, Mar 26, 2014.

  1. millpark10

    millpark10 Member HowtoForge Supporter

    Hi
    I seem to have the exact same problem as in this thread
    http://www.howtoforge.com/forums/showthread.php?t=53523
    Did it ever get solved?
    Example: I send email as a result of a filled out form on a website, those emails are sent twice.
    I fully understand why it is happening, Server 2 is supposed to be a more or less exact copy of Server 1.
    That is the whole meaning of the setup.
    But I don't need certain cronjobs to run double.
    I could let unison not copy cron catalogue (/etc/cron.d) but if Server 1 fails all cronjobs are Lost.
    Any ideas?
    //millpark10
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    Unison is not copying /etc/cron.d, at least if you used one of our setups, as the filesthereare managed by ispconfig.

    There is no easy way to prevent that the cronjobs get executed on both servers as this would have to include a machanism that a cronjob would know if a node is actively used and if a cronjob is required on both nodes or just one node.
     
  3. millpark10

    millpark10 Member HowtoForge Supporter

    Till
    You are right, of course!
    This has, as far as i can understand nothing to do with unison. First part of default.prf:
    Code:
    # Roots of the synchronization
    root = /var
    root = ssh://172.17.2.182//var/
     
    # Paths to synchronize
    path = www
    path = vmail
     
    # Some regexps specifying names and paths to ignore
    #ignore = Path stats    ## ignores /var/www/stats
    #ignore = Path stats/*  ## ignores /var/www/stats/*
    #ignore = Path */stats  ## ignores /var/www/somedir/stats, but not /var/www/a/b/c/stats
    #ignore = Name *stats   ## ignores all files/directories that end with "stats"
    #ignore = Name stats*   ## ignores all files/directories that begin with "stats"
    #ignore = Name *.tmp    ## ignores all files with the extension .tmp
       
     
    Nothing about /etc/cron.d there.
    Server1
    Code:
    root@lenny1:~/.unison# ls -las /etc/cron.d
    totalt 36
     4 drwxr-xr-x   2 root root  4096 mar 26 01:48 .
    12 drwxr-xr-x 116 root root 12288 mar 24 23:29 ..
     4 -rw-r--r--   1 root root   179 jul 30  2012 amavisd-new
     4 -rw-r--r--   1 root root   258 dec 18 14:30 awstats
     4 -rw-r--r--   1 root root    96 mar 22 23:19 ispc_chrooted_web7
     4 -rw-r--r--   1 root root   544 dec 12 05:43 php5
     4 -rw-r--r--   1 root root   102 jun 19  2012 .placeholder
    Server2
    Code:
    root@lenny2:/etc/cron.d# ls -las
    totalt 36
     4 drwxr-xr-x   2 root root  4096 mar 26 01:48 .
    12 drwxr-xr-x 116 root root 12288 mar 24 23:37 ..
     4 -rw-r--r--   1 root root   179 jul 30  2012 amavisd-new
     4 -rw-r--r--   1 root root   256 dec 18 14:44 awstats
     4 -rw-r--r--   1 root root    96 mar 22 23:19 ispc_chrooted_web7
     4 -rw-r--r--   1 root root   544 dec 12 05:43 php5
     4 -rw-r--r--   1 root root   102 jun 19  2012 .placeholder
    
    As you can see the cron job and some of the other files have the same timestamp if that might be a clue to this.
    Something is copying cron jobs to server2, I don't know what?
    Any ideas?
    (I still beleive I followed the guides, as of below the line, very thoroughly)
    //millpark10
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    The cronjobs are created by ispconfig as part of the mirroring. ispconfig can not decide if a cronjob ahs to be run on both servers or just on one server.
     
  5. philgardner

    philgardner Member

    Couldn't the cron job command be conditional, checking the hostname and only running if it was on the correct host?
     
  6. millpark10

    millpark10 Member HowtoForge Supporter

    That is actually what we are discussing to implement.
    I understand that every command I want to use in jail has to be "installed" in jail. Pls help, how can I get /bin/hostname to work in jail? (just cp to /bin in jailed web?)
    //millpark10
     
  7. till

    till Super Moderator Staff Member ISPConfig Developer

    use the jk_cp command from the jailkit utilities, to copy additional programs into the jail. example:

    jk_cp /var/www/clients/client1/web1 /bin/hostname
     
  8. millpark10

    millpark10 Member HowtoForge Supporter

    Aha, ok, thank you Till.
    Just checking, your command line sems inverted somehow, or is it in the correct order?
    jk_cp "fetches" the command into jail maybe?
    //millpark10
     
  9. till

    till Super Moderator Staff Member ISPConfig Developer

    i missed the -j parameter. See jk_cp manpage "man jk_cp":

    jk_cp -j jail source

    try:

    jk_cp -j /var/www/clients/client1/web1 /bin/hostname
     
  10. millpark10

    millpark10 Member HowtoForge Supporter

    Hi Till
    Thank you!
    I read http://olivier.sessink.nl/jailkit/ but your answer was close enough!
    Slowly working towards all the functions I need. I am genuinely happy for all the help and support. This is going to be good! :)
    //millpark10
     
  11. millpark10

    millpark10 Member HowtoForge Supporter

    Prohibit cron to run on server2 in mirrored setup

    This is our solution for cron to run on only the first server: First put command "hostname" in jail
    Code:
    server1:~# jk_cp -j /var/www/clients/client3/web5 -v /bin/hostname
    Script for cron to run:
    Code:
    #!/bin/sh
    hostname=$(hostname)
    if [ "$hostname" = "server1.example.com" ]; then
    wget otherexampleserver.net/crontest.php?hostname=$hostname -O /dev/null
    fi
    Still in the process to understand how to run wget on the same server, if possible.
    //millpark10
     
    Last edited: Mar 29, 2014

Share This Page