Module: DevDNSd::ApplicationMethods::System

Extended by:
ActiveSupport::Concern
Included in:
DevDNSd::Application
Defined in:
lib/devdnsd/application.rb

Overview

System management methods.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) action_add(options)

Adds aliases to an interface.

Parameters:

  • options (Hash)

    The options provided by the user.

Returns:

  • (Boolean)

    true if action succeeded, false otherwise.



125
126
127
# File 'lib/devdnsd/application.rb', line 125

def action_add(options)
  manage_aliases(:add, i18n.add_empty, options)
end

- (Boolean) action_install

Installs the application into the autolaunch.

Returns:

  • (Boolean)

    true if action succeeded, false otherwise.



141
142
143
# File 'lib/devdnsd/application.rb', line 141

def action_install
  manage_installation(launch_agent_path, resolver_path, :create_resolver, :create_agent, :load_agent)
end

- (Boolean) action_remove(options)

Removes aliases from an interface.

Parameters:

  • options (Hash)

    The options provided by the user.

Returns:

  • (Boolean)

    true if action succeeded, false otherwise.



133
134
135
# File 'lib/devdnsd/application.rb', line 133

def action_remove(options)
  manage_aliases(:remove, i18n.remove_empty, options)
end

- (Boolean) action_start

Starts the server in background.

Returns:

  • (Boolean)

    true if action succeeded, false otherwise.



99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/devdnsd/application.rb', line 99

def action_start
  get_logger.info(i18n.starting)

  if !Process.respond_to?(:fork) then
    logger.warn(i18n.no_fork)
    @config.foreground = true
  elsif @command.options[:foreground].value then
    @config.foreground = true
  end

  @config.foreground ? perform_server : RExec::Daemon::Controller.start(self.class)
  true
end

- (Boolean) action_stop

Stops the server in background.

Returns:

  • (Boolean)

    true if action succeeded, false otherwise.



116
117
118
119
# File 'lib/devdnsd/application.rb', line 116

def action_stop
  RExec::Daemon::Controller.stop(self.class)
  true
end

- (Boolean) action_uninstall

Uninstalls the application from the autolaunch.

Returns:

  • (Boolean)

    true if action succeeded, false otherwise.



148
149
150
# File 'lib/devdnsd/application.rb', line 148

def action_uninstall
  manage_installation(launch_agent_path, resolver_path, :delete_resolver, :unload_agent, :delete_agent)
end

- (Boolean) dns_update

Updates DNS cache.

Returns:

  • (Boolean)

    true if command succeeded, false otherwise.



82
83
84
85
# File 'lib/devdnsd/application.rb', line 82

def dns_update
  @logger.info(i18n.dns_update)
  execute_command("dscacheutil -flushcache")
end

- (Boolean) execute_command(command)

Executes a shell command.

Parameters:

  • command (String)

    The command to execute.

Returns:

  • (Boolean)

    true if command succeeded, false otherwise.



75
76
77
# File 'lib/devdnsd/application.rb', line 75

def execute_command(command)
  system(command)
end

- (Boolean) is_osx?

Checks if we are running on MacOS X.

System services are only available on that platform.

Returns:

  • (Boolean)

    true if the current platform is MacOS X, false otherwise.



92
93
94
# File 'lib/devdnsd/application.rb', line 92

def is_osx?
  ::RbConfig::CONFIG['host_os'] =~ /^darwin/
end

- (String) launch_agent_path(name = "it.cowtech.devdnsd")

Gets the path for the launch agent file.

Parameters:

  • name (String) (defaults to: "it.cowtech.devdnsd")

    The base name for the agent.

Returns:

  • (String)

    The path for the launch agent file.



67
68
69
# File 'lib/devdnsd/application.rb', line 67

def launch_agent_path(name = "it.cowtech.devdnsd")
  ENV["HOME"] + "/Library/LaunchAgents/#{name}.plist"
end

- (String) resolver_path(tld = nil)

Gets the path for the resolver file.

Parameters:

  • tld (String) (defaults to: nil)

    The TLD to manage.

Returns:

  • (String)

    The path for the resolver file.



58
59
60
61
# File 'lib/devdnsd/application.rb', line 58

def resolver_path(tld = nil)
  tld ||= @config.tld
  "/etc/resolver/#{tld}"
end