Class: Luban::Deployment::Application::Crontab

Inherits:
Worker show all
Defined in:
lib/luban/deployment/cli/application/crontab.rb

Constant Summary

Constants included from Parameters::Application

Parameters::Application::DefaultLogrotateInterval, Parameters::Application::DefaultLogrotateMaxAge

Constants included from Parameters::General

Parameters::General::DefaultLubanRootPath

Constants included from Helpers::Utils

Helpers::Utils::LogLevels

Instance Attribute Summary

Attributes inherited from Worker::Base

#task

Attributes included from Helpers::Utils

#backend

Attributes included from Helpers::Configuration

#config

Instance Method Summary collapse

Methods inherited from Worker

#bundle_command, #bundle_executable, #gemfile, #has_gemfile?, #profile_name, #release_path, #release_tag, #releases_path, #ruby_bin_path

Methods included from Service::Worker::Base

#control_file_name, #control_file_path, #log_file_name, #log_file_path, #log_path, #output_redirection, #pid_file_name, #pid_file_path, #pids_path, #profile_name, #profile_path, #service_entry, #shell_command, #shell_output, #shell_prefix

Methods included from Worker::Paths::Remote

#app_archives_path, #app_bin_path, #app_path, #app_tmp_path, #archived_logs_path, #archives_path, #current_app_path, #downloads_path, #env_path, #envrc_file, #luban_install_path, #package_bin_path, #package_install_path, #project_path, #releases_path, #shared_path, #tmp_path, #unset_envrc_file

Methods inherited from Worker::Base

#dry_run?, #force?, #initialize, #linux?, #method_missing, #osx?, #packages, #run, #target_full_name, #target_major_version, #target_name, #target_patch_level, #target_version

Methods included from Parameters::Application

#env_name, #logrotate_count, #monitor_itself?, #monitorable?

Methods included from Parameters::Base

#parameter

Methods included from Parameters::Project

#monitor_defined?, #process_monitor_via

Methods included from Parameters::General

included

Methods included from Helpers::Utils

#assure, #assure_dirs, #assure_symlink, #capture, #check_pass?, #chmod, #cp, #directory?, #exists?, #file?, #hardware_name, #host, #hostname, #ln, #match?, #md5_for, #md5_for_dir, #md5_for_file, #md5_matched?, #mkdir, #mv, #now, #os_name, #os_release, #readlink, #render_template, #revision_match?, #rm, #rmdir, #sudo, #symlink?, #touch, #truncate, #upload_by_template, #url_exists?, #user_home

Methods included from Helpers::Configuration

#ask, #fetch, #find_template_file, #load_configuration_file, #primary, #release_roles, #role, #roles, #server, #set, #set_default, #syntax_error?

Constructor Details

This class inherits a constructor from Luban::Deployment::Worker::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Luban::Deployment::Worker::Base

Instance Method Details

#cronjobsObject



5
# File 'lib/luban/deployment/cli/application/crontab.rb', line 5

def cronjobs; backend.host.cronjobs; end

#crontab_closeObject



36
37
38
# File 'lib/luban/deployment/cli/application/crontab.rb', line 36

def crontab_close
  @crontab_close ||= "# CRONTAB END : #{env_name}"
end

#crontab_file_nameObject



16
17
18
# File 'lib/luban/deployment/cli/application/crontab.rb', line 16

def crontab_file_name
  @crontab_file_name ||= "crontab"
end

#crontab_file_pathObject



8
9
10
# File 'lib/luban/deployment/cli/application/crontab.rb', line 8

def crontab_file_path
  @crontab_file_path ||= shared_path.join(crontab_file_name)
end


28
29
30
# File 'lib/luban/deployment/cli/application/crontab.rb', line 28

def crontab_footer_template_file
  @crontab_footer_template_file ||= find_template_file("crontab_footer.erb")
end

#crontab_header_template_fileObject



24
25
26
# File 'lib/luban/deployment/cli/application/crontab.rb', line 24

def crontab_header_template_file
  @crontab_header_template_file ||= find_template_file("crontab_header.erb")
end

#crontab_openObject



32
33
34
# File 'lib/luban/deployment/cli/application/crontab.rb', line 32

def crontab_open
  @crontab_open ||= "# CRONTAB BEGIN : #{env_name}"
end

#crontab_template_fileObject



20
21
22
# File 'lib/luban/deployment/cli/application/crontab.rb', line 20

def crontab_template_file
  @crontab_template_file ||= find_template_file("crontab.erb")
end

#deploy_cronjobsObject



44
45
46
47
48
49
50
# File 'lib/luban/deployment/cli/application/crontab.rb', line 44

def deploy_cronjobs
  if deploy_cronjobs!
    update_result "Successfully published #{crontab_file_name}."
  else
    update_result "Skipped! ALREADY published #{crontab_file_name}.", status: :skipped
  end
end

#has_cronjobs?Boolean

Returns:

  • (Boolean)


6
# File 'lib/luban/deployment/cli/application/crontab.rb', line 6

def has_cronjobs?; !cronjobs.empty?; end

#list_cronjobsObject



74
75
76
77
78
79
80
81
# File 'lib/luban/deployment/cli/application/crontab.rb', line 74

def list_cronjobs
  crontab = extract_crontab(task.opts.all)
  if crontab.empty?
    update_result "No crontab for #{user}."
  else
    update_result crontab
  end
end

#shell_delimiterObject



87
# File 'lib/luban/deployment/cli/application/crontab.rb', line 87

def shell_delimiter; @shell_delimiter ||= '&&'; end

#shell_setupObject



83
84
85
# File 'lib/luban/deployment/cli/application/crontab.rb', line 83

def shell_setup
  @shell_setup ||= task.opts.release.nil? ? ["source #{envrc_file}"] : super
end

#tmp_crontab_file_pathObject



12
13
14
# File 'lib/luban/deployment/cli/application/crontab.rb', line 12

def tmp_crontab_file_path
  @tmp_crontab_file_path ||= shared_path.join(".tmp.#{crontab_file_name}")
end

#update_cronjobsObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/luban/deployment/cli/application/crontab.rb', line 52

def update_cronjobs
  unless file?(crontab_file_path)
    update_result "FAILED to update crontab: missing #{crontab_file_path}.", status: :failed, level: :error
    return
  end
  if updated?
    if has_cronjobs?
      update_result "Skipped! ALREADY updated crontab.", status: :skipped
    else
      update_result "Skipped! No crontab for #{user}.", status: :skipped
    end
    return
  end

  update_cronjobs!
  if updated?
    update_result "Successfully updated crontab."
  else
    update_result "FAILED to update crontab.", status: :failed, level: :error
  end
end

#updated?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/luban/deployment/cli/application/crontab.rb', line 40

def updated?
  extract_crontab == capture(:cat, crontab_file_path, "2>/dev/null")
end