Class: Luban::Deployment::Application::Crontab
- Inherits:
-
Worker
show all
- Defined in:
- lib/luban/deployment/cli/application/crontab.rb
Constant Summary
Parameters::Application::DefaultLogrotateInterval, Parameters::Application::DefaultLogrotateMaxAge
Parameters::General::DefaultLubanRootPath
Helpers::Utils::LogLevels
Instance Attribute Summary
Attributes inherited from Worker::Base
#task
#backend
#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
#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
#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
#dry_run?, #force?, #initialize, #linux?, #method_missing, #osx?, #packages, #run, #target_full_name, #target_major_version, #target_name, #target_patch_level, #target_version
#env_name, #logrotate_count, #monitor_itself?, #monitorable?
#parameter
#monitor_defined?, #process_monitor_via
included
#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
#ask, #fetch, #find_template_file, #load_configuration_file, #primary, #release_roles, #role, #roles, #server, #set, #set_default, #syntax_error?
Instance Method Details
#cronjobs ⇒ Object
5
|
# File 'lib/luban/deployment/cli/application/crontab.rb', line 5
def cronjobs; backend.host.cronjobs; end
|
#crontab_close ⇒ Object
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_name ⇒ Object
16
17
18
|
# File 'lib/luban/deployment/cli/application/crontab.rb', line 16
def crontab_file_name
@crontab_file_name ||= "crontab"
end
|
#crontab_file_path ⇒ Object
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 ||= find_template_file("crontab_footer.erb")
end
|
24
25
26
|
# File 'lib/luban/deployment/cli/application/crontab.rb', line 24
def
@crontab_header_template_file ||= find_template_file("crontab_header.erb")
end
|
#crontab_open ⇒ Object
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_file ⇒ Object
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_cronjobs ⇒ Object
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
6
|
# File 'lib/luban/deployment/cli/application/crontab.rb', line 6
def has_cronjobs?; !cronjobs.empty?; end
|
#list_cronjobs ⇒ Object
74
75
76
77
78
79
80
81
|
# File 'lib/luban/deployment/cli/application/crontab.rb', line 74
def list_cronjobs
crontab = (task.opts.all)
if crontab.empty?
update_result "No crontab for #{user}."
else
update_result crontab
end
end
|
#shell_delimiter ⇒ Object
87
|
# File 'lib/luban/deployment/cli/application/crontab.rb', line 87
def shell_delimiter; @shell_delimiter ||= '&&'; end
|
#shell_setup ⇒ Object
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_path ⇒ Object
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_cronjobs ⇒ Object
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
40
41
42
|
# File 'lib/luban/deployment/cli/application/crontab.rb', line 40
def updated?
== capture(:cat, crontab_file_path, "2>/dev/null")
end
|