class Amnesie::Process

Public Class Methods

new(card) click to toggle source
# File lib/amnesie/process.rb, line 5
def initialize(card)
  @systemctl = Helpers::Exec.new("systemctl")
  @kill = Helpers::Exec.new("kill")
  @rm = Helpers::Exec.new("rm")
  @card = card
end

Public Instance Methods

kill() click to toggle source
# File lib/amnesie/process.rb, line 12
def kill
  kill_dhcpcd
  kill_dhclient
end
restart() click to toggle source
# File lib/amnesie/process.rb, line 17
def restart
  restart_dhcpcd
  restart_dhclient
  restart_tor
end

Private Instance Methods

kill_dhclient() click to toggle source
# File lib/amnesie/process.rb, line 32
def kill_dhclient
  return if not TTY::Which.exist?('dhclient', paths: ['/sbin'])
  pids=`pgrep -i dhclient`.chomp
  kill_pids(pids) if $?.success?

  @rm.run("/run/dhclient.#{@card}.pid") if File.exist? "/run/dhclient.#{@card}.pid"
  @rm.run("/var/lib/dhcp/dhclient.#{@card}.leases") if File.exist? "/var/lib/dhcp/dhclient.#{@card}.leases"
  puts "Killed dhclient"
end
kill_dhcpcd() click to toggle source
# File lib/amnesie/process.rb, line 25
def kill_dhcpcd
  return if not TTY::Which.exist?('dhcpcd')
  pids=`pgrep -i dhcpcd`.chomp
  kill_pids(pids) if $?.success?
  puts "Killed dhcpcd"
end
kill_pids(pids) click to toggle source
# File lib/amnesie/process.rb, line 74
def kill_pids(pids)
  pids.lines.each { |p|
    ps = p.gsub(/\n/, '')
    @kill.run("-9 #{ps}")
  }
end
restart_dhclient() click to toggle source
# File lib/amnesie/process.rb, line 53
def restart_dhclient
  return if not TTY::Which.exist?('dhclient', paths: ['/sbin'])
  dhclient = Helpers::Exec.new("dhclient")
  # command tested on debian, not try on another system yet...
  dhclient.run("-4 -v -i -pf /run/dhclient.#{@card}.pid -lf /var/lib/dhcp/dhclient.#{@card}.leases -I -df /var/lib/dhcp/dhclient6.#{@card}.leases #{@card}")
  if TTY::Which.exist?('systemctl')
    `systemctl is-active ifup@#{@card}`
    @systemctl.run("restart ifup@#{@card}") if $?.success?
  end
  puts "Restarted dhclient"
end
restart_dhcpcd() click to toggle source
# File lib/amnesie/process.rb, line 42
def restart_dhcpcd
  return if not TTY::Which.exist?('dhcpcd')
  if TTY::Which.exist?('systemctl') 
    @systemctl.run("restart dhcpcd")
  else
    dhcpcd = Helpers::Exec.new("dhcpcd")
    dhcpcd.run("-q")
  end
  puts "Restarted dhcpcd"
end
restart_tor() click to toggle source
# File lib/amnesie/process.rb, line 65
def restart_tor
  return if not TTY::Which.exist?('tor')
  if TTY::Which.exist?('systemctl') 
    `systemctl is-active tor`
    @systemctl.run("restart tor") if $?.success?
    puts "Restarted tor"
  end
end