Module: OsCtld::DistConfig::Helpers::Common

Included in:
Configurator, Network::Base
Defined in:
lib/osctld/dist_config/helpers/common.rb

Instance Method Summary collapse

Instance Method Details

#systemd_service_enabled?(service, target) ⇒ Boolean

Parameters:

  • service (String)
  • target (String)

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/osctld/dist_config/helpers/common.rb', line 33

def systemd_service_enabled?(service, target)
  wanted = File.join(
    rootfs,
    'etc/systemd/system',
    "#{target}.wants",
    service,
  )

  begin
    File.lstat(wanted)
    return true
  rescue Errno::ENOENT
    return false
  end
end

#systemd_service_masked?(service) ⇒ Boolean

Parameters:

  • service (String)

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
# File 'lib/osctld/dist_config/helpers/common.rb', line 21

def systemd_service_masked?(service)
  begin
    dst = File.readlink(File.join(rootfs, 'etc/systemd/system', service))
  rescue Errno::ENOENT, Errno::EINVAL
    return false
  else
    return dst == '/dev/null'
  end
end

#writable?(path) {|path| ... } ⇒ Boolean

Check if the file at `path` si writable by its user

If the file doesn't exist, we take it as writable. If a block is given, it is called if `path` is writable.

Yield Parameters:

  • path (String)

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
# File 'lib/osctld/dist_config/helpers/common.rb', line 9

def writable?(path)
  begin
    return if (File.stat(path).mode & 0200) != 0200
  rescue Errno::ENOENT
    # pass
  end

  yield(path) if block_given?
  true
end