Koozali.org: home of the SME Server

Obsolete Releases => SME Server 8.x => Topic started by: turandot on August 16, 2014, 10:44:48 AM

Title: How to customize Cron jobs templates for a server running one hour of a day
Post by: turandot on August 16, 2014, 10:44:48 AM
All,

I have setup SME 8.1 to run as a backup server using Affa 3: it does not provide any other services. The backup job is done every day on 06:30 am. Since the server is useless for 23 hours each day, the backup server is waked by WoL on 06:20 each day by my productive SME server. Additionally the backup server is sent back to sleep (signal-event halt) for the rest of the day on 07:20 by a custom cron job template. So far, so good.

Looking into the crontab, there are a couple of jobs that are foreseen to run at times when the server normally sleeps:
Code: [Select]
# run-parts

01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
I understand that this part is generated from /etc/e-smith/templates/etc/crontab/10runparts . Should I adapt this template e.g. to the following?
Code: [Select]
# run-parts

01 * * * * root run-parts /etc/cron.hourly
02 7 * * * root run-parts /etc/cron.daily
07 7 * * 0 root run-parts /etc/cron.weekly
12 7 1 * * root run-parts /etc/cron.monthly


What about
Code: [Select]
# logrotate
12 1 */7 * * root       /sbin/e-smith/signal-event logrotate
I understand that this part is generated from /etc/e-smith/templates/etc/crontab/65_logrotate . Should I adapt this template e.g. to the following?
Code: [Select]
    # Just for now, do it each morning. Add logic here if we want
    # to be able to tune the frequency
    my $minute = 12;
    my $hour   = 07;
    my $day    = "*/$interval";


Now  /etc/e-smith/templates/etc/crontab/check4updates . Should I adapt this template e.g. to the following?
Code: [Select]
    if ($freq eq 'weekly') {
        $min = 25;
        $dom = '*';
        $dow = 0;
    } elsif ($freq eq 'monthly') {
        $min = 25;
        $dom = 1;
        $dow = '*';
    } else {
        $min = 25;
        $dom = '*';
        $dow = '*';
    }
Squid is not used, therefore I would leave the related template /etc/e-smith/templates/etc/crontab/squid unchanged. Is this OK?


Now template /etc/e-smith/templates/etc/crontab/statusreport. Here I don't understand where the contents of the variables
Code: [Select]
    my $dow    = ${statusreport}{DayOfWeek};
    my $hour   = ${statusreport}{Hour};
    my $minute = ${statusreport}{Minute};

are coming from. As an example: how is $dow generated? Where is the variable ${statusreport}{DayOfWeek} defined? Should I change something here?

Thanks, turandot
Title: Re: How to customize Cron jobs templates for a server running one hour of a day
Post by: CharlieBrady on August 16, 2014, 03:37:17 PM
Here I don't understand where the contents of the variables
Code: [Select]
    my $dow    = ${statusreport}{DayOfWeek};
    my $hour   = ${statusreport}{Hour};
    my $minute = ${statusreport}{Minute};

are coming from. As an example: how is $dow generated? Where is the variable ${statusreport}{DayOfWeek} defined?

You either haven't read, or haven't understood, the developers' guide section about the configuration database and templates.

Within templates, all entries in the configuration database are available as pre-defined perl variables. So 'config show statusreport' is available as %statusreport within the template. So here $dow will be set to the value of 'config getprop statusreport DayOfWeek'.
Title: Re: How to customize Cron jobs templates for a server running one hour of a day
Post by: turandot on August 16, 2014, 04:50:34 PM
You either haven't read, or haven't understood, the developers' guide section about the configuration database and templates.

Within templates, all entries in the configuration database are available as pre-defined perl variables. So 'config show statusreport' is available as %statusreport within the template. So here $dow will be set to the value of 'config getprop statusreport DayOfWeek'.

Charlie,

many thanks for pointing to the predefined variables, I obviously missed that part, this is clear now.

On the other hand, other variables are "hard coded" in the templates, e.g. like those parts in /etc/e-smith/templates/etc/crontab/10runparts . Should I adapt the Cron times for my use case?

Many thanks,

turandot
Title: Re: How to customize Cron jobs templates for a server running one hour of a day
Post by: CharlieBrady on August 17, 2014, 01:05:10 AM
On the other hand, other variables are "hard coded" in the templates, e.g. like those parts in /etc/e-smith/templates/etc/crontab/10runparts . Should I adapt the Cron times for my use case?

Yes, the whole point of custom templates is that  you can change the bits that don't suit your needs.
Title: Re: How to customize Cron jobs templates for a server running one hour of a day
Post by: turandot on August 17, 2014, 09:45:45 PM
Charlie,

thanks a lot once again. I have applied the changes, and all worked out well. '/etc/crontab' looks nice now with adapted templates and properties. The jobs will run now in a time slot, where the server is up and running.

turandot
Title: Re: How to customize Cron jobs templates for a server running one hour of a day
Post by: guest22 on August 17, 2014, 10:14:40 PM
@stephdl,

shall we try to put this in a how-to wiki page with a sensible title?

guest

(typo in nick)
Title: Re: How to customize Cron jobs templates for a server running one hour of a day
Post by: janet on August 17, 2014, 10:36:39 PM
RequestedDeletion, stephdl

Quote
...a how-to wiki page with a sensible title?

It could be added here
http://wiki.contribs.org/Template_Tutorial
Title: Re: How to customize Cron jobs templates for a server running one hour of a day
Post by: guest22 on August 17, 2014, 10:41:15 PM
Janet,

thanks, good suggestion, good place.

guest
Title: Re: How to customize Cron jobs templates for a server running one hour of a day
Post by: mmccarn on August 18, 2014, 01:28:54 AM
There may be a way to use 'anacron' to automatically run your daily, weekly and monthly cronjobs without templating each job:
http://serverfault.com/questions/551425/cron-to-anacron-migration-process

Title: Re: How to customize Cron jobs templates for a server running one hour of a day
Post by: stephdl on August 18, 2014, 02:12:17 PM
RequestedDeletion, stephdl

It could be added here
http://wiki.contribs.org/Template_Tutorial
Please do it for any takers :)