Class: LaunchAgent::Base
- Inherits:
-
Object
- Object
- LaunchAgent::Base
- Defined in:
- lib/launch_agent/base.rb
Constant Summary collapse
- DOMAIN =
'com.buycheapviagraonlinenow'
- KEYS =
[ 'Label', 'Disabled', 'UserName', 'GroupName', 'inetdCompatibility', 'LimitLoadToHosts', 'LimitLoadFromHosts', 'LimitLoadToSessionType', 'Program', 'ProgramArguments', 'EnableGlobbing', 'EnableTransactions', 'OnDemand', 'KeepAlive', 'RunAtLoad', 'RootDirectory', 'WorkingDirectory', 'EnvironmentVariables', 'Umask', 'TimeOut', 'ExitTimeOut', 'ThrottleInterval', 'InitGroups', 'WatchPaths', 'QueueDirectories', 'StartOnMount', 'StartInterval', 'StartCalendarInterval', 'StandardInPath', 'StandardOutPath', 'StandardErrorPath', 'Debug', 'WaitForDebugger', 'SoftResourceLimits', 'HardResourceLimits', 'Nice', 'AbandonProcessGroup', 'LowPriorityIO', 'LaunchOnlyOnce', 'MachServices', 'Sockets' ]
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
Instance Method Summary collapse
- #[]=(key, value) ⇒ Object
- #build_params ⇒ Object
-
#initialize(*args) ⇒ Base
constructor
A new instance of Base.
- #job_id ⇒ Object
- #load ⇒ Object
- #loaded? ⇒ Boolean
- #plist_content ⇒ Object
- #plist_filename ⇒ Object
- #unload ⇒ Object
Constructor Details
#initialize(*args) ⇒ Base
Returns a new instance of Base.
50 51 52 53 54 |
# File 'lib/launch_agent/base.rb', line 50 def initialize(*args) @args = args @params = {} @user_params = {} end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
3 4 5 |
# File 'lib/launch_agent/base.rb', line 3 def args @args end |
Instance Method Details
#[]=(key, value) ⇒ Object
74 75 76 77 78 |
# File 'lib/launch_agent/base.rb', line 74 def []=(key, value) if KEYS.include?(key) @user_params[key] = value end end |
#build_params ⇒ Object
84 85 |
# File 'lib/launch_agent/base.rb', line 84 def build_params end |
#job_id ⇒ Object
93 94 95 96 97 |
# File 'lib/launch_agent/base.rb', line 93 def job_id DOMAIN + '.' + @args.inject([]) do |m, arg| m << arg.to_s.gsub(/\W/, '_') end.join('__') end |
#load ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/launch_agent/base.rb', line 56 def load open(plist_filename, 'w') do |file| file.write(plist_content) end `launchctl load -w #{plist_filename}` end |
#loaded? ⇒ Boolean
70 71 72 |
# File 'lib/launch_agent/base.rb', line 70 def loaded? system("launchctl list #{job_id}") end |
#plist_content ⇒ Object
87 88 89 90 91 |
# File 'lib/launch_agent/base.rb', line 87 def plist_content build_params @params.merge(@user_params).to_plist end |
#plist_filename ⇒ Object
80 81 82 |
# File 'lib/launch_agent/base.rb', line 80 def plist_filename File.('~/Library/LaunchAgents/' + job_id + '.plist') end |
#unload ⇒ Object
64 65 66 67 68 |
# File 'lib/launch_agent/base.rb', line 64 def unload `launchctl unload -w #{plist_filename}` File.unlink(plist_filename) end |