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

#action_installBoolean

Installs the application into the autolaunch.

Returns:

  • (Boolean)

    true if action succedeed, false otherwise.



107
108
109
# File 'lib/devdnsd/application.rb', line 107

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

#action_startBoolean

Starts the server in background.

Returns:

  • (Boolean)

    true if action succedeed, false otherwise.



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/devdnsd/application.rb', line 84

def action_start
  self.get_logger.info(self.i18n.starting)

  if !Process.respond_to?(:fork) then
    self.logger.warn(self.i18n.no_fork)
    @config.foreground = true
  end

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

#action_stopBoolean

Stops the server in background.

Returns:

  • (Boolean)

    true if action succedeed, false otherwise.



99
100
101
102
# File 'lib/devdnsd/application.rb', line 99

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

#action_uninstallBoolean

Uninstalls the application from the autolaunch.

Returns:

  • (Boolean)

    true if action succedeed, false otherwise.



114
115
116
# File 'lib/devdnsd/application.rb', line 114

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

#dns_updateBoolean

Updates DNS cache.

Returns:

  • (Boolean)

    true if command succeeded, false otherwise.



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

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

#execute_command(command) ⇒ Boolean

Executes a shell command.

Parameters:

  • command (String)

    The command to execute.

Returns:

  • (Boolean)

    true if command succeeded, false otherwise.



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

def execute_command(command)
  system(command)
end

#is_osx?Boolean

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.



77
78
79
# File 'lib/devdnsd/application.rb', line 77

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

#launch_agent_path(name = "it.cowtech.devdnsd") ⇒ String

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.



52
53
54
# File 'lib/devdnsd/application.rb', line 52

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

#resolver_path(tld = nil) ⇒ String

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.



43
44
45
46
# File 'lib/devdnsd/application.rb', line 43

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