Koozali.org: home of the SME Server

How to customize Cron jobs templates for a server running one hour of a day

Offline turandot

  • *
  • 82
  • +0/-0
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

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
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'.

Offline turandot

  • *
  • 82
  • +0/-0
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

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
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.

Offline turandot

  • *
  • 82
  • +0/-0
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

guest22

@stephdl,

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

guest

(typo in nick)

Offline janet

  • *****
  • 4,812
  • +0/-0
RequestedDeletion, stephdl

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

It could be added here
http://wiki.contribs.org/Template_Tutorial
Please search before asking, an answer may already exist.
The Search & other links to useful information are at top of Forum.

guest22

Janet,

thanks, good suggestion, good place.

guest

Offline mmccarn

  • *
  • 2,656
  • +10/-0
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


Offline stephdl

  • *
  • 1,523
  • +0/-0
    • Linux et Geekeries
RequestedDeletion, stephdl

It could be added here
http://wiki.contribs.org/Template_Tutorial
Please do it for any takers :)
See http://wiki.contribs.org/Koozali_Foundation
irc : Freenode #sme_server #sme-fr

!!! Please write your knowledge to the Wiki !!!