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)
-
- (Boolean) action_add(options)
Adds aliases to an interface.
-
- (Boolean) action_install
Installs the application into the autolaunch.
-
- (Boolean) action_remove(options)
Removes aliases from an interface.
-
- (Boolean) action_restart
Restarts the server in background.
-
- (Boolean) action_start
Starts the server in background.
-
- (Boolean) action_status
Shows the status of the server.
-
- (Boolean) action_stop
Stops the server in background.
-
- (Boolean) action_uninstall
Uninstalls the application from the autolaunch.
-
- (Boolean) dns_update
Updates DNS cache.
-
- (Boolean) execute_command(command)
Executes a shell command.
-
- (Boolean) is_osx?
Checks if we are running on MacOS X.
-
- (String) launch_agent_path(name = "it.cowtech.devdnsd")
Gets the path for the launch agent file.
-
- (String) resolver_path(tld = nil)
Gets the path for the resolver file.
Instance Method Details
- (Boolean) action_add(options)
Adds aliases to an interface.
158 159 160 |
# File 'lib/devdnsd/application.rb', line 158 def action_add() manage_aliases(:add, i18n.add_empty, ) end |
- (Boolean) action_install
Installs the application into the autolaunch.
174 175 176 |
# File 'lib/devdnsd/application.rb', line 174 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.
166 167 168 |
# File 'lib/devdnsd/application.rb', line 166 def action_remove() manage_aliases(:remove, i18n.remove_empty, ) end |
- (Boolean) action_restart
Restarts the server in background.
132 133 134 135 136 |
# File 'lib/devdnsd/application.rb', line 132 def action_restart action_stop action_start true end |
- (Boolean) action_start
Starts the server in background.
107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/devdnsd/application.rb', line 107 def action_start get_logger.info(i18n.starting) if !Process.respond_to?(:fork) then logger.warn(i18n.no_fork) @config.foreground = true elsif @command.[:foreground].value then @config.foreground = true end @config.foreground ? perform_server : RExec::Daemon::Controller.start(self.class) true end |
- (Boolean) action_status
Shows the status of the server
141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/devdnsd/application.rb', line 141 def action_status daemon = self.class status = RExec::Daemon::ProcessFile.status(daemon) pid = RExec::Daemon::ProcessFile.recall(daemon).to_s status = :crashed if status == :unknown && daemon.crashed? if status == :running then logger.info(replace_markers(i18n.status_running(pid))) elsif logger.info(replace_markers(i18n.send("status_#{status}"))) end end |
- (Boolean) action_stop
Stops the server in background.
124 125 126 127 |
# File 'lib/devdnsd/application.rb', line 124 def action_stop RExec::Daemon::Controller.stop(self.class) true end |
- (Boolean) action_uninstall
Uninstalls the application from the autolaunch.
181 182 183 |
# File 'lib/devdnsd/application.rb', line 181 def action_uninstall manage_installation(launch_agent_path, resolver_path, :delete_resolver, :unload_agent, :delete_agent) end |
- (Boolean) dns_update
Updates DNS cache.
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/devdnsd/application.rb', line 82 def dns_update @logger.info(i18n.dns_update) script = Tempfile.new("devdnsd-dns-cache-script") script.write("dscacheutil -flushcache 2&>1 > /dev/null\n") script.write("killall -9 mDNSResponder 2&>1 > /dev/null\n") script.write("killall -9 mDNSResponderHelper 2&>1 > /dev/null\n") script.close Kernel.system("/usr/bin/osascript -e 'do shell script \"sh #{script.path}\" with administrator privileges' 2&>1 > /dev/null") script.unlink end |
- (Boolean) execute_command(command)
Executes a shell command.
75 76 77 |
# File 'lib/devdnsd/application.rb', line 75 def execute_command(command) system("#{command} 2&>1 > /dev/null") end |
- (Boolean) is_osx?
Checks if we are running on MacOS X.
System services are only available on that platform.
100 101 102 |
# File 'lib/devdnsd/application.rb', line 100 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.
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.
58 59 60 61 |
# File 'lib/devdnsd/application.rb', line 58 def resolver_path(tld = nil) tld ||= @config.tld "/etc/resolver/#{tld}" end |