Class: VagrantPlugins::SyncedFolderNFSGuest::GuestRedHat::Cap::NFSServer

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-nfs_guest/guests/redhat/cap/nfs_server.rb

Class Method Summary collapse

Class Method Details

.firewalld?(machine) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/vagrant-nfs_guest/guests/redhat/cap/nfs_server.rb', line 11

def self.firewalld?(machine)
  machine.communicate.test("test $(command -v firewall-cmd)")
end

.firewalld_enabled?(machine) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/vagrant-nfs_guest/guests/redhat/cap/nfs_server.rb', line 15

def self.firewalld_enabled?(machine)
  machine.communicate.test("test $(firewall-cmd --state) == 'running'")
end

.nfs_check_command(machine) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/vagrant-nfs_guest/guests/redhat/cap/nfs_server.rb', line 73

def self.nfs_check_command(machine)
  if systemd?(machine)
    machine.communicate.test(
      "systemctl status rpcbind nfs-server"
    )
  else
    machine.communicate.test(
      "service nfs status"
    )
  end
end

.nfs_server_install(machine) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/vagrant-nfs_guest/guests/redhat/cap/nfs_server.rb', line 19

def self.nfs_server_install(machine)
  machine.communicate.sudo("yum -y install nfs-utils nfs-utils-lib")

  if systemd?(machine)
    machine.communicate.sudo("systemctl enable rpcbind nfs-server")
  else
    machine.communicate.sudo("chkconfig nfs on")

  end
end

.nfs_server_installed(machine) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/vagrant-nfs_guest/guests/redhat/cap/nfs_server.rb', line 65

def self.nfs_server_installed(machine)
  if systemd?(machine)
    machine.communicate.test("systemctl status nfs-server.service")
  else
    machine.communicate.test("service nfs status")
  end
end

.nfs_setup_firewall(machine, ip) ⇒ Object



30
31
32
33
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
# File 'lib/vagrant-nfs_guest/guests/redhat/cap/nfs_server.rb', line 30

def self.nfs_setup_firewall(machine, ip)
  if not systemd?(machine)
    # centos 6.5 has iptables on by default is would seem
    machine.communicate.sudo(
      "sed -i \"s/#LOCKD_/LOCKD_/\" /etc/sysconfig/nfs"
    )
    machine.communicate.sudo(
      "sed -i \"s/#MOUNTD_PORT/MOUNTD_PORT/\" /etc/sysconfig/nfs"
    )
    machine.communicate.sudo(
      "iptables -I INPUT -m state --state NEW -p udp -m multiport " +
      "--dport 111,892,2049,32803 -s #{ip}/32 -j ACCEPT"
    )
    machine.communicate.sudo(
      "iptables -I INPUT -m state --state NEW -p tcp -m multiport " +
      "--dport 111,892,2049,32803 -s #{ip}/32 -j ACCEPT"
    )

    nfs_start_command(machine)
  end

  puts("*******************************")
  puts(firewalld?(machine))
  puts(firewalld_enabled?(machine))
  puts("*******************************")

  if firewalld?(machine) #and firewalld_enabled?(machine)
    # add nfs rules if we have firewalld and it's enabled
    machine.communicate.sudo("firewall-cmd --permanent --add-service=nfs")
    machine.communicate.sudo("firewall-cmd --permanent --add-service=mountd")
    machine.communicate.sudo("firewall-cmd --permanent --add-service=rpc-bind")
    machine.communicate.sudo("firewall-cmd --reload")
  end
end

.nfs_start_command(machine) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/vagrant-nfs_guest/guests/redhat/cap/nfs_server.rb', line 85

def self.nfs_start_command(machine)
  if systemd?(machine)
    machine.communicate.sudo(
      "systemctl start rpcbind nfs-server",
      error_class: Errors::GuestNFSError,
      error_key: :nfs_start_failed
    )
  else
    ['rpcbind', 'nfs'].each do |i|
      machine.communicate.sudo(
        "service #{i} restart",
        error_class: Errors::GuestNFSError,
        error_key: :nfs_start_failed
      )
    end
  end
end

.systemd?(machine) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/vagrant-nfs_guest/guests/redhat/cap/nfs_server.rb', line 7

def self.systemd?(machine)
  machine.communicate.test("test $(ps -o comm= 1) == 'systemd'")
end