Module: MiGA::Cli::Action::Init::DaemonHelper
- Included in:
- MiGA::Cli::Action::Init
- Defined in:
- lib/miga/cli/action/init/daemon_helper.rb
Overview
Helper module with daemon configuration functions for MiGA::Cli::Action::Init
Instance Method Summary collapse
- #configure_bash_daemon(v) ⇒ Object
- #configure_daemon ⇒ Object
- #configure_qsub_msub_daemon(v) ⇒ Object
- #configure_slurm_daemon(v) ⇒ Object
- #configure_ssh_daemon(v) ⇒ Object
Instance Method Details
#configure_bash_daemon(v) ⇒ Object
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 |
# File 'lib/miga/cli/action/init/daemon_helper.rb', line 34 def configure_bash_daemon(v) v[:latency] = cli.ask_user('How long should I sleep? (in secs)', '2').to_i v[:maxjobs] = cli.ask_user('How many jobs can I launch at once?', '6').to_i v[:ppn] = cli.ask_user('How many CPUs can I use per job?', '2').to_i v[:nodelist] = nil # <- To enable non-default with default SSH cli.puts 'Setting up internal daemon defaults.' cli.puts 'If you don\'t understand this just leave default values:' v[:cmd] = cli.ask_user( "How should I launch tasks?\n" \ " {{variables}}: script, vars, cpus, log, task_name, miga\n ", "{{vars}} {{miga}} run -r '{{script}}' -l '{{log}}' -e" ) v[:var] = cli.ask_user( "How should I pass variables?\n" \ " {{variables}}: key, value\n ", "{{key}}={{value}}" ) v[:varsep] = cli.ask_user('What should I use to separate variables?', ' ') v[:alive] = cli.ask_user( "How can I know that a process is still alive?\n" \ " Output should be 1 for running and 0 for non-running\n" \ " {{variables}}: pid\n ", "ps -p '{{pid}}' | tail -n +2 | wc -l" ) v[:kill] = cli.ask_user( "How should I terminate tasks?\n" \ " {{variables}}: pid\n ", "kill -9 '{{pid}}'" ) v end |
#configure_daemon ⇒ Object
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 |
# File 'lib/miga/cli/action/init/daemon_helper.rb', line 6 def configure_daemon cli.puts 'Default daemon configuration:' daemon_f = File.('.miga_daemon.json', ENV['MIGA_HOME']) unless File.exist?(daemon_f) and cli.ask_user( 'A template daemon already exists, do you want to preserve it?', 'yes', %w(yes no) ) == 'yes' v = { created: Time.now.to_s, updated: Time.now.to_s } v[:type] = cli.ask_user( 'Please select the type of daemon you want to setup', cli[:dtype], %w(bash ssh qsub msub slurm) ) case v[:type] when 'bash' v = configure_bash_daemon(v) when 'ssh' v = configure_ssh_daemon(v) when 'slurm' v = configure_slurm_daemon(v) else # [qm]sub v = configure_qsub_msub_daemon(v) end v[:format_version] = 1 File.open(daemon_f, 'w') { |fh| fh.puts JSON.pretty_generate(v) } end cli.puts '' end |
#configure_qsub_msub_daemon(v) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/miga/cli/action/init/daemon_helper.rb', line 138 def configure_qsub_msub_daemon(v) flavor = v[:type] == 'msub' ? 'msub' : cli.ask_user('Select qsub flavor', 'torque', %w[torque sge]) queue = cli.ask_user('What queue should I use?', nil, nil, true) v[:latency] = cli.ask_user('How long should I sleep? (in secs)', '150').to_i v[:maxjobs] = cli.ask_user('How many jobs can I launch at once?', '300').to_i v[:ppn] = cli.ask_user('How many CPUs can I use per job?', '2').to_i v[:nodelist] = nil # <- To enable non-default with default SSH cli.puts 'Setting up internal daemon defaults.' cli.puts 'If you don\'t understand this just leave default values:' if flavor == 'sge' v[:cmd] = cli.ask_user( "How should I launch tasks?\n" \ " {{variables}}: script, vars, cpus, log, task_name, task_name_simple\n ", "#{v[:type]} -q '#{queue}' -v '{{vars}}' -pe openmp {{cpus}} " \ "-j y -o '{{log}}' -N '{{task_name_simple}}' -l h_vmem=9g " \ "-l h_rt=12:00:00 '{{script}}' | grep . " \ "| perl -pe 's/^Your job (\\S+) .*/$1/'" ) else v[:cmd] = cli.ask_user( "How should I launch tasks?\n" \ " {{variables}}: script, vars, cpus, log, task_name, task_name_simple\n ", "#{v[:type]} -q '#{queue}' -v '{{vars}}' -l nodes=1:ppn={{cpus}} " \ "-j oe -o '{{log}}' -N '{{task_name}}' -l mem=9g " \ "-l walltime=12:00:00 '{{script}}' | grep ." ) end v[:var] = cli.ask_user( "How should I pass variables?\n" \ " {{variables}}: key, value\n ", "{{key}}={{value}}" ) v[:varsep] = cli.ask_user( 'What should I use to separate variables?', ',' ) if v[:type] == 'qsub' if flavor == 'sge' v[:alive] = cli.ask_user( "How can I know that a process is still alive?\n" \ " Output should be 1 for running and 0 for non-running\n" \ " {{variables}}: pid\n ", "qstat -j '{{pid}}' -s pr 2>/dev/null | head -n 1 | wc -l " \ "| awk '{print $1}'" ) else v[:alive] = cli.ask_user( "How can I know that a process is still alive?\n" \ " Output should be 1 for running and 0 for non-running\n" \ " {{variables}}: pid\n ", "qstat -f '{{pid}}' | grep ' job_state =' | perl -pe 's/.*= //' " \ "| grep '[^C]' | tail -n 1 | wc -l | awk '{print $1}'" ) end v[:kill] = cli.ask_user( "How should I terminate tasks?\n" \ " {{variables}}: pid\n ", "qdel '{{pid}}'" ) else # msub v[:alive] = cli.ask_user( "How can I know that a process is still alive?\n" \ " Output should be 1 for running and 0 for non-running\n" \ " {{variables}}: pid\n ", "checkjob '{{pid}}'|grep '^State:' | perl -pe 's/.*: //' " \ "| grep 'Deferred\\|Hold\\|Idle\\|Starting\\|Running\\|Blocked'" \ "| tail -n 1 | wc -l | awk '{print $1}'" ) v[:kill] = cli.ask_user( "How should I terminate tasks?\n" \ " {{variables}}: pid\n ", "canceljob '{{pid}}'" ) end v end |
#configure_slurm_daemon(v) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/miga/cli/action/init/daemon_helper.rb', line 99 def configure_slurm_daemon(v) queue = cli.ask_user('What queue should I use?', nil, nil, true) v[:latency] = cli.ask_user('How long should I sleep? (in secs)', '150').to_i v[:maxjobs] = cli.ask_user('How many jobs can I launch at once?', '300').to_i v[:ppn] = cli.ask_user('How many CPUs can I use per job?', '2').to_i v[:nodelist] = nil # <- To enable non-default with default SSH cli.puts 'Setting up internal daemon defaults' cli.puts 'If you don\'t understand this just leave default values:' v[:cmd] = cli.ask_user( "How should I launch tasks?\n" \ " {{variables}}: script, vars, cpus, log, task_name, miga\n ", "{{vars}} sbatch --partition='#{queue}' --export=ALL " \ "--nodes=1 --ntasks-per-node={{cpus}} --output='{{log}}' " \ "--job-name='{{task_name}}' --mem=9G --time=12:00:00 {{script}} " \ "| perl -pe 's/.* //'" ) v[:var] = cli.ask_user( "How should I pass variables?\n" \ " {{variables}}: key, value\n ", "{{key}}={{value}}" ) v[:varsep] = cli.ask_user( 'What should I use to separate variables?', ' ' ) v[:alive] = cli.ask_user( "How can I know that a process is still alive?\n" \ " Output should be 1 for running and 0 for non-running\n" \ " {{variables}}: pid\n ", "squeue -h -o %t -j '{{pid}}' | grep '^PD\\|R\\|CF\\|CG$' " \ "| tail -n 1 | wc -l" ) v[:kill] = cli.ask_user( "How should I terminate tasks?\n" \ " {{variables}}: pid\n ", "scancel '{{pid}}'" ) v end |
#configure_ssh_daemon(v) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/miga/cli/action/init/daemon_helper.rb', line 66 def configure_ssh_daemon(v) v[:latency] = cli.ask_user('How long should I sleep? (in secs)', '3').to_i v[:nodelist] = cli.ask_user( 'What environmental variable points to node list?', '$MIGA_NODELIST' ) v[:ppn] = cli.ask_user('How many CPUs can I use per job?', '2').to_i cli.puts 'Setting up internal daemon defaults.' cli.puts 'If you don\'t understand this just leave default values:' v[:cmd] = cli.ask_user( "How should I launch tasks?\n" \ " {{variables}}: script, vars, cpus, log, task_name, miga, host\n ", "{{vars}} {{miga}} run -r '{{script}}' -l '{{log}}' -R {{host}} -e" ) v[:var] = cli.ask_user( "How should I pass variables?\n" \ " {{variables}}: key, value\n ", "{{key}}={{value}}" ) v[:varsep] = cli.ask_user('What should I use to separate variables?', ' ') v[:alive] = cli.ask_user( "How can I know that a process is still alive?\n" \ " Output should be 1 for running and 0 for non-running\n" \ " {{variables}}: pid\n ", "ps -p '{{pid}}' | tail -n +2 | wc -l" ) v[:kill] = cli.ask_user( "How should I terminate tasks?\n" \ " {{variables}}: pid\n ", "kill -9 '{{pid}}'" ) v end |