Class: TaskLoop::Shutdown

Inherits:
Command
  • Object
show all
Defined in:
lib/taskloop/command/shutdown.rb

Constant Summary

Constants inherited from Command

Command::DOLPHIN, Command::LOGO

Instance Method Summary collapse

Methods inherited from Command

#create_dir_if_needed, #create_file_if_needed, #create_taskloop_file_structure_if_needed, #initialize, #taskloop_cron_log_path, #taskloop_cron_tab_path, #taskloop_data_dir, #taskloop_data_proj_dirs, #taskloop_dir, #taskloop_environments_path, #taskloop_proj_list_dirs, #taskloop_proj_list_path, #taskloop_taskfile_paths, #tasklooprc_path

Constructor Details

This class inherits a constructor from TaskLoop::Command

Instance Method Details

#runObject



12
13
14
15
# File 'lib/taskloop/command/shutdown.rb', line 12

def run
  super
  unregister_taskloop_from_crontab_if_needed
end

#unregister_taskloop_from_crontab_if_neededObject



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
# File 'lib/taskloop/command/shutdown.rb', line 17

def unregister_taskloop_from_crontab_if_needed
  system("crontab -l > #{taskloop_cron_tab_path}")
  registered = false
  pattern = /\A\* \* \* \* \* sh ~\/\.tasklooprc/
  remain = []
  File.open(taskloop_cron_tab_path, "r").each_line do |line|
    if line.match?(pattern)
      registered = true
    else
      remain << line
    end
  end

  unless registered
    puts "Warning: taskloop has already shutdown. Please do not shutdown again.".ansi.yellow
    puts "    If your want to launch taskloop, please execute the `taskloop launch` command.".ansi.yellow
    return
  end

  File.open(taskloop_cron_tab_path, "w") do |file|
    file.write(remain.join)
  end

  system("crontab #{taskloop_cron_tab_path}")

  puts LOGO.ansi.blue
  puts "    taskloop has shutdown successfully. ".ansi.blue
  puts ""
  puts "    byeeeeeeeeeeeeeeeee !".ansi.blue
  puts ""
end