1

I have a Daemon coded in C to copy a file from local to remote using RSYNC and update the same file after every 5 second.
Everything works fine but when the while loop has executed for say 10 to 15 times RSYNC fails.

Here is the segment of code:

    #define SHELLSCRIPT "\
    #! /bin/bash \n\
    rsync -azh /my_daemon_test -e 'ssh -p 2222' username@domainname.com:~ \n\
    "


   syslog(LOG_NOTICE, "Successfully started daemon\n");

    while(1) {
            syslog(LOG_NOTICE, "daemon in while loop : %d\n", flag);
            sys_ret = system(SHELLSCRIPT);
            syslog(LOG_NOTICE, "RSYNC Executed %d\n", sys_ret);
            sleep(5);
            flag++;
    }

Log

Dec 18 00:07:08 localhost ./mydaemon[26384]: daemon in while loop : 10
Dec 18 00:07:09 localhost ./mydaemon[26384]: RSYNC Executed 0
Dec 18 00:07:14 localhost ./mydaemon[26384]: daemon in while loop : 11
Dec 18 00:07:15 localhost ./mydaemon[26384]: RSYNC Executed 0 <==== Success
Dec 18 00:07:20 localhost ./mydaemon[26384]: daemon in while loop : 12
Dec 18 00:07:20 localhost ./mydaemon[26384]: RSYNC Executed 65280 <==== Failed
Dec 18 00:07:25 localhost ./mydaemon[26384]: daemon in while loop : 13
Dec 18 00:07:26 localhost ./mydaemon[26384]: RSYNC Executed 65280

Need help to maintain the consistency.

Thanks

Community
  • 1
  • 1
Jayzcode
  • 1,305
  • 14
  • 15
  • 2
    What does rsync and ssh say when it fails? It's entirely possible that you're running into anti-denial-of-service heuristics here --- making a connection every five seconds is rather frequent... – David Given Dec 17 '13 at 19:12
  • Since the code is for daemon STDIN, STDOUT, STDERR are closed, so all I have is logs. I can try with sleep(10) and see if it helps. – Jayzcode Dec 17 '13 at 19:24
  • @DavidGiven: with sleep(5) rsync failed after 1min 15sec, but with sleep(10) it is around 10 mins and rsync hasn't failed yet. I think all is good now. Thanks – Jayzcode Dec 17 '13 at 19:35
  • That does sound like anti-denial-of-service. You should try to avoid polling the server so frequently at all --- you'll be ringing all sorts of alarm bells in the server logs. I'd be hesitant about anything more frequent than once every ten minutes. – David Given Dec 18 '13 at 13:30
  • @DavidGiven: Thanks. In real case I have it twice a day. This was just a part of test to see if daemon worked the way I wanted. – Jayzcode Mar 14 '14 at 09:38

0 Answers0