Module: OsCtld::DistConfig::Helpers::Common
- Included in:
- Configurator, Network::Base
- Defined in:
- lib/osctld/dist_config/helpers/common.rb
Instance Method Summary collapse
- #systemd_service_enabled?(service, target) ⇒ Boolean
- #systemd_service_masked?(service) ⇒ Boolean
-
#writable?(path) {|path| ... } ⇒ Boolean
Check if the file at ‘path` si writable by its user.
Instance Method Details
#systemd_service_enabled?(service, target) ⇒ Boolean
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/osctld/dist_config/helpers/common.rb', line 31 def systemd_service_enabled?(service, target) wanted = File.join( rootfs, 'etc/systemd/system', "#{target}.wants", service ) begin File.lstat(wanted) true rescue Errno::ENOENT false end end |
#systemd_service_masked?(service) ⇒ Boolean
21 22 23 24 25 26 27 |
# File 'lib/osctld/dist_config/helpers/common.rb', line 21 def systemd_service_masked?(service) dst = File.readlink(File.join(rootfs, 'etc/systemd/system', service)) rescue Errno::ENOENT, Errno::EINVAL false else dst == '/dev/null' 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.
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 false if (File.stat(path).mode & 0o200) != 0o200 rescue Errno::ENOENT # pass end yield(path) if block_given? true end |