Class: AmazonKamal::Cli::Timers

Inherits:
Kamal::Cli::Base
  • Object
show all
Defined in:
lib/amazon_kamal/cli/timers.rb

Instance Method Summary collapse

Instance Method Details

#addObject



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
# File 'lib/amazon_kamal/cli/timers.rb', line 5

def add
  say "Adding systemd timers to #{KAMAL.primary_host}...", :magenta

  path = options[:systemd_path]

  timers do |timer|
    say "Adding timer: #{timer}"

    on(KAMAL.primary_host) do
      # Upload files
      puts method(:upload!).source_location.inspect
      upload!("#{path}/#{timer}.timer", "/tmp")
      upload!("#{path}/#{timer}.service", "/tmp")

      as "root" do
        # Move files to systemd directory and set permissions
        execute :mv, "/tmp/#{timer}.*", "/etc/systemd/system/"
        execute :chown, "root:root", "/etc/systemd/system/#{timer}.*"
        execute :chmod, "644", "/etc/systemd/system/#{timer}.*"

        # Enable and start the timer
        execute :systemctl, "daemon-reload"
        execute :systemctl, "enable --now #{timer}.timer"
      end
    end
  end
end

#removeObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/amazon_kamal/cli/timers.rb', line 34

def remove
  say "Removing systemd timers from #{KAMAL.primary_host}...", :magenta

  timers do |timer|
    puts "Removing timer: #{timer}"

    on(KAMAL.primary_host) do
      as "root" do
        # Stop and disable the timer
        execute :systemctl, "stop #{timer}.timer"
        execute :systemctl, "disable #{timer}.timer"

        # Remove timer files
        execute :rm, "/etc/systemd/system/#{timer}.*"

        # Reload systemd daemon
        execute :systemctl, "daemon-reload"
      end
    end
  end
end

#showObject



57
58
59
60
61
62
# File 'lib/amazon_kamal/cli/timers.rb', line 57

def show
  say "Calling systemctl list-timers on #{KAMAL.primary_host}...", :magenta
  on(KAMAL.primary_host) do
    puts capture(:systemctl, "list-timers")
  end
end