cron.daily not executing properly

  • Hi guys,


    I'm using Openmediavault for about two years now. I am very happy having it and I was able to solve all of my problems with this forum and google. Unfortunately my luck came to an end a few days ago.


    Beforehand I want to say, like most people asking questions here, I am not the most experienced linux-professional, so please excuse if I ask for something obvious.


    My Problem:
    I have several folders shared via samba, which is working great. Some weeks ago I thought maybe having a recycle bin would be cool so I set it up and set it to automatically recycle everything older than 14 days. It took some time until I realized, that the automatic deletion does not work at all. I did some reading and could find out, that the recycle scripts are executed from a script within the /etc/cron.daily folder named "openmediavault-samba-recycle", which again is executed by anacron, if I understood correctly. I first checked if all the scripts exist and are executable and everything seems to be in order. So I placed a script there myself which just appends the current date to a file, to see if all the scripts in /etc/cron.daily are beeing executed once a day. This is a list of all the scripts in my cron.daily folder:


    0anacron
    apt
    bsdmainutils
    dpkg
    logrotate
    man-db
    ntp
    openmediavault-cron-apt
    openmediavault-flush-mailq
    openmediavault-mdadm
    openmediavault-pending_config_changes
    openmediavault-samba-recycle
    passwd
    quota
    samba
    sysstat


    I played around a bit and to my surprise found out that my test script is beeing executed if it is called "crontest", but not, if it starts with a letter coming later in the alphabet. So my guess was, that when anacron executes all the scripts in the folder, during the execution of some script, some kind of error occurs, which is why all the following scripts in alphabetical order are not executed. So I placed a test script between each of the actual scripts in the folder, to see which is the last actual script that executes. With this method I could find, that all my test scripts were executed that were placed before "openmediavault-cron-apt", and none of the ones placed after it, which explains why the samba recycle script never does its job.


    I'm not sure if it makes any sense what I was doing up to now, but anyway I've reached a point where I'm stuck. I don't know if my conclusion is correct, that openmediavault-cron-apt is not working correctly and if so how I can find out what is wrong. I hope you can give a hint into the right direction.


    Thank you in advance for your help!

    OMV Stoneburner | ASRock H77M-ITX | Intel Core i3-3240 | 4GB RAM | Kingston SSDNow 30GB System | 3 x 2TB RAID 5 Data

    • Offizieller Beitrag

    cron.daily gets executed by the anacrontab, if you go there is (etc/anacrontab)


    run-parts --report /etc/cron.daily


    You can add a verbose switch to run manually and to see if run-parts if picking the script and it should since it just process all the folder, unless the execution bit was taken from a particular script.


    Now this is just a matter of executing manually the script, to see what's it really doing


    /etc/cron.daily/./openmediavault-samba-recycle


    does not show that much since the output is nulled, you can maybe alter here a little bit to show more output with set -x and remove the stdout redirection.


    Now if you open that you'll see another-run parts to another folder /var/lib/openmediavault/cron.d/ where you should find a prefixed file/script with "samba-recycle-" in the name. See if that running script is correctly configured for deleting the recycle.

  • Thank you for your reply!


    I forgot to add earlier, I already tried manually running the samba recycle script and it worked well. So I think it really is a matter of not being executed.


    However, I did as you said, I checked the anacrontab, it seems to be in order, it looks like this:


    # /etc/anacrontab: configuration file for anacron


    # See anacron(8) and anacrontab(5) for details.


    SHELL=/bin/sh
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    HOME=/root
    LOGNAME=root


    # These replace cron's entries
    1 5 cron.daily run-parts --report /etc/cron.daily
    7 10 cron.weekly run-parts --report /etc/cron.weekly
    @monthly 15 cron.monthly run-parts --report /etc/cron.monthly


    Then I ran "run-parts --verbose /etc/cron.daily 2> /home/outputtest" and and realized that it did the full job. I can check in the output, that it ran every single script in /etc/cron.daily - of course - including the recycle script.


    So why does anacron, when acting on its own, stop executing scripts at openmediavault-cron-apt?

    OMV Stoneburner | ASRock H77M-ITX | Intel Core i3-3240 | 4GB RAM | Kingston SSDNow 30GB System | 3 x 2TB RAID 5 Data

    • Offizieller Beitrag

    Don't know, somehow yesterday I thought about cron-apt and I just came to my mind that I haven't received mails in a while. Deep investigation show me that I have a missing file in action.d folder in cron-apt folder. Nothing to do with your case but also made me notice that all cron executions are logged. Check the syslog with entries prefixed with CRON to see if is really called during uptime of the server. I don't use the recycle bin but I'll try to setup vm to see what's going on. Is this 2.0 or 3.0?

  • I'm on OMV 2.2.5!


    Again, I can see with the testscripts I created, that anacron started the cron.daily jobs today in the morning and stopped execution somewhere around the cron-apt script.


    I was checking the syslog for cron entries. Cron-apt did execute 4 times yesterday, but I don't know which of those times it did run because I manually started it and weather it ran on its own so I'm gonna check back on that tomorrow and see if it was executed today by anacron.


    But I realized something else. I was also checking on anacron's entries in syslog and found the following:


    Anacron started the cron.weekly job today. "cat /var/log/syslog | grep anacron" yields the following:



    Jul 24 10:42:58 kila-nas anacron[2534]: Anacron 2.3 started on 2016-07-24
    Jul 24 10:42:58 kila-nas anacron[2534]: Will run job `cron.weekly' in 10 min.
    Jul 24 10:42:58 kila-nas anacron[2534]: Jobs will be executed sequentially
    Jul 24 10:52:58 kila-nas anacron[2534]: Job `cron.weekly' started
    Jul 24 10:52:58 kila-nas anacron[4797]: Updated timestamp for job `cron.weekly' to 2016-07-24
    Jul 24 10:53:01 kila-nas anacron[2534]: Job `cron.weekly' terminated (mailing output)
    Jul 24 10:53:01 kila-nas anacron[2534]: Normal exit (1 job run)


    When anacron starts the cron.daily job, it always looks like this:


    Jul 24 08:30:38 kila-nas anacron[2484]: Anacron 2.3 started on 2016-07-24
    Jul 24 08:30:38 kila-nas anacron[2484]: Will run job `cron.daily' in 5 min.
    Jul 24 08:30:38 kila-nas anacron[2484]: Will run job `cron.weekly' in 10 min.
    Jul 24 08:30:38 kila-nas anacron[2484]: Jobs will be executed sequentially
    Jul 24 08:35:38 kila-nas anacron[2484]: Job `cron.daily' started
    Jul 24 08:35:38 kila-nas anacron[4200]: Updated timestamp for job `cron.daily' to 2016-07-24


    and then there are no more anacron entries until the next reboot. So when running cron.daily it updates the timestamp, but never terminates the execution and sends a notification mail. I don't know why I never though about not receiving cron.daily mails. Since I never ever got them it seemed normal for me.


    This at least tells us, that there is no problem with the recycle script, since I set it up only a few weeks ago, but never received the cron.daily notification mails at all. So the problem was there before.

    OMV Stoneburner | ASRock H77M-ITX | Intel Core i3-3240 | 4GB RAM | Kingston SSDNow 30GB System | 3 x 2TB RAID 5 Data

  • I could find the problem finally. I am using autoshutdown, which turns off my NAS if it is not being used for 15 minutes. My NAS is automatically turned on every day early in the morning for some of my cron-jobs to execute and, since it is not used afterwards, it shuts down 15 minutes after that. I can't really see why, but anacron updates the timestamp when STARTING the daily jobs instead of when actually finishing it. So the timestamp is always updated during these 15 minutes and no matter if the daily jobs ever finish, anacron never tries to run them again that day. I was then checking the cron-apt script since it seemed to me anacron did not finish executing that in particular and found that for some reason cron-apt sleeps for a random time up to an hour before starting the actual script. In my case this is fatal, because before the timer ends, my NAS is shutdown again by autoshutdown, anacron thinks the daily job is finished, but many of the scripts (cron-apt and everything that comes afterwards) were never executed at all. And this happened every day, propably since I am using OMV.


    However, I set the sleeping period to zero in the cron-apt script, so instead of close to an hour, the daily cron jobs are finished in less than 10 seconds now, which is fast enough to not be disrupted by autoshutdown.


    Actually I'm quite glad, I encountered this problem by chance because of activating the recycle bin. Chances are good I would never have realized, that half of the cron.daily scripts are never executed.


    Anyway, thank you subzero for all the input! It helped a lot on my way to the solution!

    OMV Stoneburner | ASRock H77M-ITX | Intel Core i3-3240 | 4GB RAM | Kingston SSDNow 30GB System | 3 x 2TB RAID 5 Data

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!