File: Cron.pm

package info (click to toggle)
librunapp-perl 0.13-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 232 kB
  • sloc: perl: 2,521; makefile: 2
file content (66 lines) | stat: -rwxr-xr-x 1,102 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
=head1 NAME

RunApp::Cron - build and install/remove a crontab

=head1 DESCRIPTION

A RunApp controller that will build from template and install/remove a crontab

=cut

package RunApp::Cron;
use warnings;
use strict;
use Cwd;
use File::Spec::Functions;

use base qw( RunApp::Template );

=head2 new()

creates a new controller

=cut

sub new {
  my $self = shift;
  $self = $self->SUPER::new(@_);
  unless ($self->{source}) {
    $self->{source} = catfile(cwd(), "templates", "crontab",
      $self->{file} =~ /crontab_master/ ? "crontab_master" : "crontab_slave"
    );
  
    if (! -e $self->{source}) {
      warn "source file $self->{source} doesn't exist";
      $self->{source} = \"";
    }
  }
  return $self;
}

=head2 start()

installs the crontab

=cut

sub start {
  my $self = shift;
  die "no generated file" unless $self->{file};
  my $user = $self->{user} ? "-u $self->{user}" : "";
  print `crontab $user $self->{file}`;
}

=head2 stop()

removes the crontab

=cut

sub stop {
  my $self = shift;
  my $user = $self->{user} ? "-u $self->{user}" : "";
  print `crontab $user -r`;
}

1;