launch 1.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ ### 2.0.0
2
+
3
+ * Rewrote whole gem
4
+ * New job checkin: Launch::Job.checkin
5
+ * New API:
6
+ * Launch.jobs
7
+ * Launch::Job: checkin, find, #remove, #start, #stop, #submit
8
+
9
+ ### 1.0 / 2011-02-26
10
+
11
+ * Major enhancements
12
+ * Birthday!
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2011 by Samuel Kadolph
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,65 @@
1
+ # launch
2
+
3
+ launch is a wrapper for launchd which lets you load, unload, reload, submit, remove, start, stop and list jobs for
4
+ launchd as well as checkin from a process spawned by launchd and retrieve the sockets for the job that spawned the process.
5
+
6
+ launchd is an open source framework for launching and managing daemons, programs and scripts provided by Apple.
7
+
8
+ ## Installing
9
+
10
+ ### Recommended
11
+
12
+ ```
13
+ gem install launch
14
+ ```
15
+
16
+ ### Edge
17
+
18
+ ```
19
+ git clone https://github.com/samuelkadolph/ruby-launch
20
+ cd ruby-launch && rake install
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ Submit and remove jobs.
26
+
27
+ ```ruby
28
+ require "launch"
29
+
30
+ job = Launch::Job.new
31
+ job.label = "org.ruby.foo"
32
+ job.program = "/usr/bin/foo"
33
+ job.submit # => true
34
+
35
+ job.remove # => true
36
+ ```
37
+
38
+ Start and stop jobs.
39
+
40
+ ```ruby
41
+ require "launch"
42
+
43
+ job = Launch::Job.find("org.ruby.foo")
44
+ job.start # => true
45
+ sleep 5
46
+ job.stop # => true
47
+ ```
48
+
49
+ ## Requirements
50
+
51
+ A system with launchd installed.
52
+
53
+ ## Developers
54
+
55
+ ### Contributing
56
+
57
+ Pull requests are the desired method of contributing.
58
+
59
+ ### Running Tests
60
+
61
+ ```
62
+ bundle install
63
+ rake install
64
+ rake test
65
+ ```
@@ -0,0 +1,17 @@
1
+ require "mkmf"
2
+
3
+ abort "errno.h is required" unless have_header("errno.h")
4
+ abort "launch.h is required" unless have_header("launch.h")
5
+
6
+ unless have_header("ruby/io.h") or have_header("rubyio.h")
7
+ abort "ruby/io.h or rubyio.h is required"
8
+ end
9
+
10
+ unless have_struct_member("rb_io_t", "fd", "ruby/io.h") or have_struct_member("rb_io_t", "f", %w[ruby.h rubyio.h])
11
+ abort "rb_io_t.fd or rb_io_t.f is required"
12
+ end
13
+
14
+ # $defs << "-HAVE_RUBY_19" if RUBY_VERSION >= "1.9"
15
+ # $CFLAGS << " -Werror"
16
+
17
+ create_makefile "launch"
@@ -0,0 +1,272 @@
1
+ #include <errno.h>
2
+ #include <launch.h>
3
+ #include <ruby.h>
4
+ #include <ruby/st.h>
5
+ #include <ruby/version.h>
6
+
7
+ #ifdef HAVE_RUBY_IO_H
8
+ #include <ruby/io.h>
9
+ #elif defined(HAVE_RUBYIO_H)
10
+ #include <rubyio.h>
11
+ #endif
12
+
13
+ VALUE rb_mLaunch;
14
+ VALUE rb_mLaunchMessages;
15
+ VALUE rb_cLaunchError;
16
+ VALUE rb_cLaunchJob;
17
+ VALUE rb_cLaunchJobSocket;
18
+
19
+ static launch_data_t ruby_to_launch_data(VALUE);
20
+ static VALUE launch_data_to_ruby(launch_data_t);
21
+
22
+ static int ruby_to_launch_data_hash_iterator(VALUE key, VALUE value, VALUE dict)
23
+ {
24
+ launch_data_t key_item = ruby_to_launch_data(key);
25
+ launch_data_dict_insert((launch_data_t)dict, ruby_to_launch_data(value), launch_data_get_string(key_item));
26
+ launch_data_free(key_item);
27
+ return ST_CONTINUE;
28
+ }
29
+
30
+ static launch_data_t ruby_to_launch_data(VALUE obj)
31
+ {
32
+ launch_data_t result = NULL;
33
+ long i;
34
+ rb_io_t * fptr;
35
+
36
+ switch(TYPE(obj))
37
+ {
38
+ case T_HASH:
39
+ result = launch_data_alloc(LAUNCH_DATA_DICTIONARY);
40
+ rb_hash_foreach(obj, ruby_to_launch_data_hash_iterator, (VALUE)result);
41
+ break;
42
+ case T_ARRAY:
43
+ result = launch_data_alloc(LAUNCH_DATA_ARRAY);
44
+ for (i = 0; i < RARRAY_LEN(obj); i++)
45
+ launch_data_array_set_index(result, ruby_to_launch_data(RARRAY_PTR(obj)[i]), i);
46
+ break;
47
+ case T_FIXNUM:
48
+ case T_BIGNUM:
49
+ result = launch_data_new_integer(NUM2LONG(obj));
50
+ break;
51
+ case T_FLOAT:
52
+ result = launch_data_new_real(NUM2DBL(obj));
53
+ break;
54
+ case T_TRUE:
55
+ result = launch_data_new_bool(TRUE);
56
+ break;
57
+ case T_FALSE:
58
+ result = launch_data_new_bool(FALSE);
59
+ break;
60
+ case T_STRING:
61
+ obj = rb_str_to_str(obj);
62
+ result = launch_data_new_string(StringValueCStr(obj));
63
+ break;
64
+ case T_FILE:
65
+ GetOpenFile(obj, fptr);
66
+ #ifdef HAVE_RB_IO_T_FD
67
+ result = launch_data_new_fd((int)fptr->fd);
68
+ #elif defined(HAVE_ST_F)
69
+ result = launch_data_new_fd(fileno(fptr->f));
70
+ #endif
71
+ break;
72
+ default:
73
+ rb_raise(rb_eTypeError, "can't convert %s to launch data", rb_obj_classname(obj));
74
+ }
75
+
76
+ return result;
77
+ }
78
+
79
+ static void launch_data_to_ruby_dict_iterator(launch_data_t item, const char * key, void * hash)
80
+ {
81
+ rb_hash_aset((VALUE)hash, rb_str_new2(key), launch_data_to_ruby(item));
82
+ }
83
+
84
+ static VALUE launch_data_to_ruby(launch_data_t item)
85
+ {
86
+ VALUE result = Qnil;
87
+ size_t i, count;
88
+ int fd;
89
+
90
+ switch(launch_data_get_type(item))
91
+ {
92
+ case LAUNCH_DATA_DICTIONARY:
93
+ result = rb_hash_new();
94
+ launch_data_dict_iterate(item, launch_data_to_ruby_dict_iterator, (void *)result);
95
+ break;
96
+ case LAUNCH_DATA_ARRAY:
97
+ count = launch_data_array_get_count(item);
98
+ result = rb_ary_new2(count);
99
+ for (i = 0; i < count; i++)
100
+ rb_ary_store(result, i, launch_data_to_ruby(launch_data_array_get_index(item, i)));
101
+ break;
102
+ case LAUNCH_DATA_FD:
103
+ fd = launch_data_get_fd(item);
104
+ if (fd >= 0)
105
+ result = rb_funcall(rb_path2class("TCPServer"), rb_intern("for_fd"), 1, INT2NUM(launch_data_get_fd(item)));
106
+ else
107
+ result = INT2NUM(launch_data_get_fd(item));
108
+ break;
109
+ case LAUNCH_DATA_INTEGER:
110
+ result = LONG2NUM(launch_data_get_integer(item));
111
+ break;
112
+ case LAUNCH_DATA_REAL:
113
+ result = DBL2NUM(launch_data_get_real(item));
114
+ break;
115
+ case LAUNCH_DATA_BOOL:
116
+ result = launch_data_get_bool(item) == TRUE ? Qtrue : Qfalse;
117
+ break;
118
+ case LAUNCH_DATA_STRING:
119
+ result = rb_str_new2(launch_data_get_string(item));
120
+ break;
121
+ case LAUNCH_DATA_OPAQUE:
122
+ result = rb_str_new(launch_data_get_opaque(item), launch_data_get_opaque_size(item));
123
+ break;
124
+ case LAUNCH_DATA_ERRNO:
125
+ errno = launch_data_get_errno(item);
126
+ if (errno)
127
+ rb_sys_fail("launch");
128
+ else
129
+ result = Qtrue;
130
+ break;
131
+ case LAUNCH_DATA_MACHPORT:
132
+ break;
133
+ default:
134
+ rb_warn("unknown launch_data_type_t %d", launch_data_get_type(item));
135
+ break;
136
+ }
137
+
138
+ return result;
139
+ }
140
+
141
+ static VALUE launch_message(VALUE self, VALUE obj)
142
+ {
143
+ VALUE result = Qnil;
144
+ launch_data_t item, response;
145
+
146
+ item = ruby_to_launch_data(obj);
147
+ if (item == NULL)
148
+ rb_raise(rb_cLaunchError, "item is nil");
149
+
150
+ response = launch_msg(item);
151
+ launch_data_free(item);
152
+
153
+ if (response == NULL)
154
+ rb_sys_fail("launch");\
155
+
156
+ result = launch_data_to_ruby(response);
157
+ launch_data_free(response);
158
+
159
+ return result;
160
+ }
161
+
162
+ void Init_launch()
163
+ {
164
+ rb_require("socket");
165
+
166
+ rb_mLaunch = rb_define_module("Launch");
167
+ rb_define_singleton_method(rb_mLaunch, "message", launch_message, 1);
168
+
169
+ rb_mLaunchMessages = rb_define_module_under(rb_mLaunch, "Messages");
170
+ rb_const_set(rb_mLaunchMessages, rb_intern("SUBMITJOB"), rb_str_new2(LAUNCH_KEY_SUBMITJOB));
171
+ rb_const_set(rb_mLaunchMessages, rb_intern("REMOVEJOB"), rb_str_new2(LAUNCH_KEY_REMOVEJOB));
172
+ rb_const_set(rb_mLaunchMessages, rb_intern("STARTJOB"), rb_str_new2(LAUNCH_KEY_STARTJOB));
173
+ rb_const_set(rb_mLaunchMessages, rb_intern("STOPJOB"), rb_str_new2(LAUNCH_KEY_STOPJOB));
174
+ rb_const_set(rb_mLaunchMessages, rb_intern("GETJOB"), rb_str_new2(LAUNCH_KEY_GETJOB));
175
+ rb_const_set(rb_mLaunchMessages, rb_intern("GETJOBS"), rb_str_new2(LAUNCH_KEY_GETJOBS));
176
+ rb_const_set(rb_mLaunchMessages, rb_intern("CHECKIN"), rb_str_new2(LAUNCH_KEY_CHECKIN));
177
+
178
+ rb_cLaunchError = rb_define_class_under(rb_mLaunch, "Error", rb_eStandardError);
179
+
180
+ rb_cLaunchJob = rb_define_class_under(rb_mLaunch, "Job", rb_cObject);
181
+ rb_const_set(rb_cLaunchJob, rb_intern("LABEL"), rb_str_new2(LAUNCH_JOBKEY_LABEL));
182
+ rb_const_set(rb_cLaunchJob, rb_intern("DISABLED"), rb_str_new2(LAUNCH_JOBKEY_DISABLED));
183
+ rb_const_set(rb_cLaunchJob, rb_intern("USERNAME"), rb_str_new2(LAUNCH_JOBKEY_USERNAME));
184
+ rb_const_set(rb_cLaunchJob, rb_intern("GROUPNAME"), rb_str_new2(LAUNCH_JOBKEY_GROUPNAME));
185
+ rb_const_set(rb_cLaunchJob, rb_intern("TIMEOUT"), rb_str_new2(LAUNCH_JOBKEY_TIMEOUT));
186
+ rb_const_set(rb_cLaunchJob, rb_intern("EXITTIMEOUT"), rb_str_new2(LAUNCH_JOBKEY_EXITTIMEOUT));
187
+ rb_const_set(rb_cLaunchJob, rb_intern("INITGROUPS"), rb_str_new2(LAUNCH_JOBKEY_INITGROUPS));
188
+ rb_const_set(rb_cLaunchJob, rb_intern("SOCKETS"), rb_str_new2(LAUNCH_JOBKEY_SOCKETS));
189
+ rb_const_set(rb_cLaunchJob, rb_intern("MACHSERVICES"), rb_str_new2(LAUNCH_JOBKEY_MACHSERVICES));
190
+ rb_const_set(rb_cLaunchJob, rb_intern("MACHSERVICELOOKUPPOLICIES"), rb_str_new2(LAUNCH_JOBKEY_MACHSERVICELOOKUPPOLICIES));
191
+ rb_const_set(rb_cLaunchJob, rb_intern("INETDCOMPATIBILITY"), rb_str_new2(LAUNCH_JOBKEY_INETDCOMPATIBILITY));
192
+ rb_const_set(rb_cLaunchJob, rb_intern("ENABLEGLOBBING"), rb_str_new2(LAUNCH_JOBKEY_ENABLEGLOBBING));
193
+ rb_const_set(rb_cLaunchJob, rb_intern("PROGRAMARGUMENTS"), rb_str_new2(LAUNCH_JOBKEY_PROGRAMARGUMENTS));
194
+ rb_const_set(rb_cLaunchJob, rb_intern("PROGRAM"), rb_str_new2(LAUNCH_JOBKEY_PROGRAM));
195
+ rb_const_set(rb_cLaunchJob, rb_intern("ONDEMAND"), rb_str_new2(LAUNCH_JOBKEY_ONDEMAND));
196
+ rb_const_set(rb_cLaunchJob, rb_intern("KEEPALIVE"), rb_str_new2(LAUNCH_JOBKEY_KEEPALIVE));
197
+ rb_const_set(rb_cLaunchJob, rb_intern("LIMITLOADTOHOSTS"), rb_str_new2(LAUNCH_JOBKEY_LIMITLOADTOHOSTS));
198
+ rb_const_set(rb_cLaunchJob, rb_intern("LIMITLOADFROMHOSTS"), rb_str_new2(LAUNCH_JOBKEY_LIMITLOADFROMHOSTS));
199
+ rb_const_set(rb_cLaunchJob, rb_intern("LIMITLOADTOSESSIONTYPE"), rb_str_new2(LAUNCH_JOBKEY_LIMITLOADTOSESSIONTYPE));
200
+ rb_const_set(rb_cLaunchJob, rb_intern("RUNATLOAD"), rb_str_new2(LAUNCH_JOBKEY_RUNATLOAD));
201
+ rb_const_set(rb_cLaunchJob, rb_intern("ROOTDIRECTORY"), rb_str_new2(LAUNCH_JOBKEY_ROOTDIRECTORY));
202
+ rb_const_set(rb_cLaunchJob, rb_intern("WORKINGDIRECTORY"), rb_str_new2(LAUNCH_JOBKEY_WORKINGDIRECTORY));
203
+ rb_const_set(rb_cLaunchJob, rb_intern("ENVIRONMENTVARIABLES"), rb_str_new2(LAUNCH_JOBKEY_ENVIRONMENTVARIABLES));
204
+ rb_const_set(rb_cLaunchJob, rb_intern("USERENVIRONMENTVARIABLES"), rb_str_new2(LAUNCH_JOBKEY_USERENVIRONMENTVARIABLES));
205
+ rb_const_set(rb_cLaunchJob, rb_intern("UMASK"), rb_str_new2(LAUNCH_JOBKEY_UMASK));
206
+ rb_const_set(rb_cLaunchJob, rb_intern("NICE"), rb_str_new2(LAUNCH_JOBKEY_NICE));
207
+ rb_const_set(rb_cLaunchJob, rb_intern("HOPEFULLYEXITSFIRST"), rb_str_new2(LAUNCH_JOBKEY_HOPEFULLYEXITSFIRST));
208
+ rb_const_set(rb_cLaunchJob, rb_intern("HOPEFULLYEXITSLAST"), rb_str_new2(LAUNCH_JOBKEY_HOPEFULLYEXITSLAST));
209
+ rb_const_set(rb_cLaunchJob, rb_intern("LOWPRIORITYIO"), rb_str_new2(LAUNCH_JOBKEY_LOWPRIORITYIO));
210
+ rb_const_set(rb_cLaunchJob, rb_intern("SESSIONCREATE"), rb_str_new2(LAUNCH_JOBKEY_SESSIONCREATE));
211
+ rb_const_set(rb_cLaunchJob, rb_intern("STARTONMOUNT"), rb_str_new2(LAUNCH_JOBKEY_STARTONMOUNT));
212
+ rb_const_set(rb_cLaunchJob, rb_intern("SOFTRESOURCELIMITS"), rb_str_new2(LAUNCH_JOBKEY_SOFTRESOURCELIMITS));
213
+ rb_const_set(rb_cLaunchJob, rb_intern("HARDRESOURCELIMITS"), rb_str_new2(LAUNCH_JOBKEY_HARDRESOURCELIMITS));
214
+ rb_const_set(rb_cLaunchJob, rb_intern("STANDARDINPATH"), rb_str_new2(LAUNCH_JOBKEY_STANDARDINPATH));
215
+ rb_const_set(rb_cLaunchJob, rb_intern("STANDARDOUTPATH"), rb_str_new2(LAUNCH_JOBKEY_STANDARDOUTPATH));
216
+ rb_const_set(rb_cLaunchJob, rb_intern("STANDARDERRORPATH"), rb_str_new2(LAUNCH_JOBKEY_STANDARDERRORPATH));
217
+ rb_const_set(rb_cLaunchJob, rb_intern("DEBUG"), rb_str_new2(LAUNCH_JOBKEY_DEBUG));
218
+ rb_const_set(rb_cLaunchJob, rb_intern("WAITFORDEBUGGER"), rb_str_new2(LAUNCH_JOBKEY_WAITFORDEBUGGER));
219
+ rb_const_set(rb_cLaunchJob, rb_intern("QUEUEDIRECTORIES"), rb_str_new2(LAUNCH_JOBKEY_QUEUEDIRECTORIES));
220
+ rb_const_set(rb_cLaunchJob, rb_intern("WATCHPATHS"), rb_str_new2(LAUNCH_JOBKEY_WATCHPATHS));
221
+ rb_const_set(rb_cLaunchJob, rb_intern("STARTINTERVAL"), rb_str_new2(LAUNCH_JOBKEY_STARTINTERVAL));
222
+ rb_const_set(rb_cLaunchJob, rb_intern("STARTCALENDARINTERVAL"), rb_str_new2(LAUNCH_JOBKEY_STARTCALENDARINTERVAL));
223
+ rb_const_set(rb_cLaunchJob, rb_intern("BONJOURFDS"), rb_str_new2(LAUNCH_JOBKEY_BONJOURFDS));
224
+ rb_const_set(rb_cLaunchJob, rb_intern("LASTEXITSTATUS"), rb_str_new2(LAUNCH_JOBKEY_LASTEXITSTATUS));
225
+ rb_const_set(rb_cLaunchJob, rb_intern("PID"), rb_str_new2(LAUNCH_JOBKEY_PID));
226
+ rb_const_set(rb_cLaunchJob, rb_intern("THROTTLEINTERVAL"), rb_str_new2(LAUNCH_JOBKEY_THROTTLEINTERVAL));
227
+ rb_const_set(rb_cLaunchJob, rb_intern("LAUNCHONLYONCE"), rb_str_new2(LAUNCH_JOBKEY_LAUNCHONLYONCE));
228
+ rb_const_set(rb_cLaunchJob, rb_intern("ABANDONPROCESSGROUP"), rb_str_new2(LAUNCH_JOBKEY_ABANDONPROCESSGROUP));
229
+ rb_const_set(rb_cLaunchJob, rb_intern("IGNOREPROCESSGROUPATSHUTDOWN"), rb_str_new2(LAUNCH_JOBKEY_IGNOREPROCESSGROUPATSHUTDOWN));
230
+ rb_const_set(rb_cLaunchJob, rb_intern("POLICIES"), rb_str_new2(LAUNCH_JOBKEY_POLICIES));
231
+ rb_const_set(rb_cLaunchJob, rb_intern("ENABLETRANSACTIONS"), rb_str_new2(LAUNCH_JOBKEY_ENABLETRANSACTIONS));
232
+ rb_const_set(rb_cLaunchJob, rb_intern("POLICY_DENYCREATINGOTHERJOBS"), rb_str_new2(LAUNCH_JOBPOLICY_DENYCREATINGOTHERJOBS));
233
+ rb_const_set(rb_cLaunchJob, rb_intern("INETDCOMPATIBILITY_WAIT"), rb_str_new2(LAUNCH_JOBINETDCOMPATIBILITY_WAIT));
234
+ rb_const_set(rb_cLaunchJob, rb_intern("MACH_RESETATCLOSE"), rb_str_new2(LAUNCH_JOBKEY_MACH_RESETATCLOSE));
235
+ rb_const_set(rb_cLaunchJob, rb_intern("MACH_HIDEUNTILCHECKIN"), rb_str_new2(LAUNCH_JOBKEY_MACH_HIDEUNTILCHECKIN));
236
+ rb_const_set(rb_cLaunchJob, rb_intern("MACH_DRAINMESSAGESONCRASH"), rb_str_new2(LAUNCH_JOBKEY_MACH_DRAINMESSAGESONCRASH));
237
+ rb_const_set(rb_cLaunchJob, rb_intern("KEEPALIVE_SUCCESSFULEXIT"), rb_str_new2(LAUNCH_JOBKEY_KEEPALIVE_SUCCESSFULEXIT));
238
+ rb_const_set(rb_cLaunchJob, rb_intern("KEEPALIVE_NETWORKSTATE"), rb_str_new2(LAUNCH_JOBKEY_KEEPALIVE_NETWORKSTATE));
239
+ rb_const_set(rb_cLaunchJob, rb_intern("KEEPALIVE_PATHSTATE"), rb_str_new2(LAUNCH_JOBKEY_KEEPALIVE_PATHSTATE));
240
+ rb_const_set(rb_cLaunchJob, rb_intern("KEEPALIVE_OTHERJOBACTIVE"), rb_str_new2(LAUNCH_JOBKEY_KEEPALIVE_OTHERJOBACTIVE));
241
+ rb_const_set(rb_cLaunchJob, rb_intern("KEEPALIVE_OTHERJOBENABLED"), rb_str_new2(LAUNCH_JOBKEY_KEEPALIVE_OTHERJOBENABLED));
242
+ rb_const_set(rb_cLaunchJob, rb_intern("KEEPALIVE_AFTERINITIALDEMAND"), rb_str_new2(LAUNCH_JOBKEY_KEEPALIVE_AFTERINITIALDEMAND));
243
+ rb_const_set(rb_cLaunchJob, rb_intern("CAL_MINUTE"), rb_str_new2(LAUNCH_JOBKEY_CAL_MINUTE));
244
+ rb_const_set(rb_cLaunchJob, rb_intern("CAL_HOUR"), rb_str_new2(LAUNCH_JOBKEY_CAL_HOUR));
245
+ rb_const_set(rb_cLaunchJob, rb_intern("CAL_DAY"), rb_str_new2(LAUNCH_JOBKEY_CAL_DAY));
246
+ rb_const_set(rb_cLaunchJob, rb_intern("CAL_WEEKDAY"), rb_str_new2(LAUNCH_JOBKEY_CAL_WEEKDAY));
247
+ rb_const_set(rb_cLaunchJob, rb_intern("CAL_MONTH"), rb_str_new2(LAUNCH_JOBKEY_CAL_MONTH));
248
+ rb_const_set(rb_cLaunchJob, rb_intern("RESOURCELIMIT_CORE"), rb_str_new2(LAUNCH_JOBKEY_RESOURCELIMIT_CORE));
249
+ rb_const_set(rb_cLaunchJob, rb_intern("RESOURCELIMIT_CPU"), rb_str_new2(LAUNCH_JOBKEY_RESOURCELIMIT_CPU));
250
+ rb_const_set(rb_cLaunchJob, rb_intern("RESOURCELIMIT_DATA"), rb_str_new2(LAUNCH_JOBKEY_RESOURCELIMIT_DATA));
251
+ rb_const_set(rb_cLaunchJob, rb_intern("RESOURCELIMIT_FSIZE"), rb_str_new2(LAUNCH_JOBKEY_RESOURCELIMIT_FSIZE));
252
+ rb_const_set(rb_cLaunchJob, rb_intern("RESOURCELIMIT_MEMLOCK"), rb_str_new2(LAUNCH_JOBKEY_RESOURCELIMIT_MEMLOCK));
253
+ rb_const_set(rb_cLaunchJob, rb_intern("RESOURCELIMIT_NOFILE"), rb_str_new2(LAUNCH_JOBKEY_RESOURCELIMIT_NOFILE));
254
+ rb_const_set(rb_cLaunchJob, rb_intern("RESOURCELIMIT_NPROC"), rb_str_new2(LAUNCH_JOBKEY_RESOURCELIMIT_NPROC));
255
+ rb_const_set(rb_cLaunchJob, rb_intern("RESOURCELIMIT_RSS"), rb_str_new2(LAUNCH_JOBKEY_RESOURCELIMIT_RSS));
256
+ rb_const_set(rb_cLaunchJob, rb_intern("RESOURCELIMIT_STACK"), rb_str_new2(LAUNCH_JOBKEY_RESOURCELIMIT_STACK));
257
+ rb_const_set(rb_cLaunchJob, rb_intern("DISABLED_MACHINETYPE"), rb_str_new2(LAUNCH_JOBKEY_DISABLED_MACHINETYPE));
258
+ rb_const_set(rb_cLaunchJob, rb_intern("DISABLED_MODELNAME"), rb_str_new2(LAUNCH_JOBKEY_DISABLED_MODELNAME));
259
+
260
+ rb_cLaunchJobSocket = rb_define_class_under(rb_cLaunchJob, "Socket", rb_path2class("TCPSocket"));
261
+ rb_const_set(rb_cLaunchJobSocket, rb_intern("TYPE"), rb_str_new2(LAUNCH_JOBSOCKETKEY_TYPE));
262
+ rb_const_set(rb_cLaunchJobSocket, rb_intern("PASSIVE"), rb_str_new2(LAUNCH_JOBSOCKETKEY_PASSIVE));
263
+ rb_const_set(rb_cLaunchJobSocket, rb_intern("BONJOUR"), rb_str_new2(LAUNCH_JOBSOCKETKEY_BONJOUR));
264
+ rb_const_set(rb_cLaunchJobSocket, rb_intern("SECUREWITHKEY"), rb_str_new2(LAUNCH_JOBSOCKETKEY_SECUREWITHKEY));
265
+ rb_const_set(rb_cLaunchJobSocket, rb_intern("PATHNAME"), rb_str_new2(LAUNCH_JOBSOCKETKEY_PATHNAME));
266
+ rb_const_set(rb_cLaunchJobSocket, rb_intern("PATHMODE"), rb_str_new2(LAUNCH_JOBSOCKETKEY_PATHMODE));
267
+ rb_const_set(rb_cLaunchJobSocket, rb_intern("NODENAME"), rb_str_new2(LAUNCH_JOBSOCKETKEY_NODENAME));
268
+ rb_const_set(rb_cLaunchJobSocket, rb_intern("SERVICENAME"), rb_str_new2(LAUNCH_JOBSOCKETKEY_SERVICENAME));
269
+ rb_const_set(rb_cLaunchJobSocket, rb_intern("FAMILY"), rb_str_new2(LAUNCH_JOBSOCKETKEY_FAMILY));
270
+ rb_const_set(rb_cLaunchJobSocket, rb_intern("PROTOCOL"), rb_str_new2(LAUNCH_JOBSOCKETKEY_PROTOCOL));
271
+ rb_const_set(rb_cLaunchJobSocket, rb_intern("MULTICASTGROUP"), rb_str_new2(LAUNCH_JOBSOCKETKEY_MULTICASTGROUP));
272
+ }
Binary file
@@ -1,86 +1,13 @@
1
- ##
2
- # Launch is a wrapper for the launch(3) API for daemons and agents spawned by
3
- # launchd(8).
4
- #
5
- # Launch agents and daemons MUST NOT:
6
- #
7
- # * Call daemon(3)
8
- # * Do the equivalent of daemon(3) by calling fork and having the parent exit
9
- #
10
- # Launch agents and daemons SHOULD NOT do the following as part of their
11
- # starup initialization:
12
- #
13
- # * Set the user ID or group ID (Process::Sys.setuid, Process::Sys.setgid and
14
- # friends)
15
- # * Setup the working directory (Dir.chdir)
16
- # * chroot(2)
17
- # * setsid(2) (Process.setsid)
18
- # * Close "stray" file descriptors
19
- # * Change stdio(3) to /dev/null (STDOUT.reopen and friends)
20
- # * Setup resource limits with setrusage (Process.setrlimit)
21
- # * Ignore the SIGTERM signal (trap 'TERM', 'IGNORE')
22
- #
23
- # The above is from launchd.plist(5). Please read it for further details.
24
- #
25
- # To shut down cleanly <tt>trap 'TERM'</tt> and perform any shutdown steps
26
- # before exiting.
1
+ require "socket"
2
+ require "launch.so"
27
3
 
28
4
  module Launch
5
+ require "launch/version"
6
+ require "launch/job"
29
7
 
30
- ##
31
- # The version of launch you are using
32
-
33
- VERSION = '1.0'
34
-
35
- ##
36
- # Checks in with launch and retrieves the agent's configuration. The
37
- # configuration can be retrieved later through <tt>@launch_checkin<tt>.
38
-
39
- def launch_checkin
40
- response = launch_message Launch::Key::CHECKIN
41
-
42
- return if response.nil?
43
-
44
- @launch_checkin = response
45
- end
46
-
47
- ##
48
- # Creates ruby sockets from the sockets list in +name+.
49
- # <tt>socket_class.for_fd</tt> is called for each socket in the named list.
50
- #
51
- # +name+ comes from the socket's name key in the launchd plist.
52
- #
53
- # Example plist Sockets dictionary:
54
- #
55
- # <key>Sockets</key>
56
- # <dict>
57
- # <key>EchoSocket</key>
58
- # <dict>
59
- # <key>SockServiceName</key>
60
- # <string>12345</string>
61
- # </dict>
62
- # </dict>
63
- #
64
- # Example call:
65
- #
66
- # servers = launch_sockets 'Echo', TCPServer
67
- #
68
- # p servers.map { |server| server.addr }
69
-
70
- def launch_sockets name, socket_class
71
- require 'socket'
72
-
73
- sockets = @launch_checkin[Launch::JobKey::SOCKETS][name]
74
-
75
- raise Error, "no sockets found for #{name.inspect}" unless sockets
76
-
77
- sockets.map do |fd|
78
- socket_class.for_fd fd
8
+ class << self
9
+ def jobs
10
+ message(Messages::GETJOBS).values.map(&Job.method(:from_launch))
79
11
  end
80
12
  end
81
-
82
13
  end
83
-
84
- require 'launch/launch'
85
- require 'socket'
86
-