Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/msf/util/service_helper.rb
Views: 11780
require 'open3'12module Msf3module Util4class ServiceHelper5def self.run_cmd(cmd, input: nil, env: {}, debug: false)6exitstatus = 07err = out = ""89$stdout.puts "run_cmd: cmd=#{cmd}, input=#{input}, env=#{env}" if debug1011Open3.popen3(env, cmd) do |stdin, stdout, stderr, wait_thr|12stdin.puts(input) if input13if debug14err = stderr.read15out = stdout.read16end17exitstatus = wait_thr.value.exitstatus18end1920if exitstatus != 021if debug22$stdout.puts "'#{cmd}' returned #{exitstatus}"23$stdout.puts out24$stdout.puts err25end26end2728exitstatus29end3031def self.process_active?(pid)32begin33Process.kill(0, pid)34true35rescue Errno::ESRCH36false37end38end3940def self.tail(file)41begin42File.readlines(file).last.to_s.strip43rescue44nil45end46end4748def self.thin_cmd(conf:, address:, port:, ssl:, ssl_key:, ssl_cert:, ssl_disable_verify:,49env: 'production', daemonize:, log:, pid:, tag:)50server_opts = "--rackup #{conf} --address #{address} --port #{port}"51ssl_opts = ssl ? "--ssl --ssl-key-file #{ssl_key} --ssl-cert-file #{ssl_cert}" : ''52ssl_opts << ' --ssl-disable-verify' if ssl_disable_verify53adapter_opts = "--environment #{env}"54daemon_opts = daemonize ? "--daemonize --log #{log} --pid #{pid} --tag #{tag}" : ''55all_opts = [server_opts, ssl_opts, adapter_opts, daemon_opts].reject(&:empty?).join(' ')5657"thin #{all_opts}"58end59end60end61end626364