trinidad_init_services 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +3 -0
  3. data/History.txt +6 -0
  4. data/README.md +95 -0
  5. data/Rakefile +9 -58
  6. data/bin/trinidad_init_service +3 -4
  7. data/init.d/trinidad.erb +33 -12
  8. data/jsvc-unix-src/CHANGES.txt +62 -0
  9. data/jsvc-unix-src/INSTALL.txt +81 -0
  10. data/jsvc-unix-src/Makedefs.in +32 -0
  11. data/jsvc-unix-src/Makefile.in +42 -0
  12. data/jsvc-unix-src/configure +4417 -0
  13. data/jsvc-unix-src/configure.in +141 -0
  14. data/jsvc-unix-src/man/README +20 -0
  15. data/jsvc-unix-src/man/fetch.sh +36 -0
  16. data/jsvc-unix-src/man/jsvc.1.xml +214 -0
  17. data/jsvc-unix-src/native/.indent.pro +7 -0
  18. data/jsvc-unix-src/native/Makefile.in +46 -0
  19. data/jsvc-unix-src/native/arguments.c +476 -0
  20. data/jsvc-unix-src/native/arguments.h +94 -0
  21. data/jsvc-unix-src/native/debug.c +87 -0
  22. data/jsvc-unix-src/native/debug.h +65 -0
  23. data/jsvc-unix-src/native/dso-dlfcn.c +62 -0
  24. data/jsvc-unix-src/native/dso-dyld.c +153 -0
  25. data/jsvc-unix-src/native/dso.h +38 -0
  26. data/jsvc-unix-src/native/help.c +106 -0
  27. data/jsvc-unix-src/native/help.h +24 -0
  28. data/jsvc-unix-src/native/home.c +265 -0
  29. data/jsvc-unix-src/native/home.h +47 -0
  30. data/jsvc-unix-src/native/java.c +608 -0
  31. data/jsvc-unix-src/native/java.h +35 -0
  32. data/jsvc-unix-src/native/jsvc-unix.c +1267 -0
  33. data/jsvc-unix-src/native/jsvc.h +55 -0
  34. data/jsvc-unix-src/native/location.c +151 -0
  35. data/jsvc-unix-src/native/location.h +29 -0
  36. data/jsvc-unix-src/native/locks.c +52 -0
  37. data/jsvc-unix-src/native/locks.h +40 -0
  38. data/jsvc-unix-src/native/replace.c +121 -0
  39. data/jsvc-unix-src/native/replace.h +39 -0
  40. data/jsvc-unix-src/native/signals.c +105 -0
  41. data/jsvc-unix-src/native/signals.h +34 -0
  42. data/jsvc-unix-src/native/version.h +63 -0
  43. data/jsvc-unix-src/support/apfunctions.m4 +110 -0
  44. data/jsvc-unix-src/support/apjava.m4 +94 -0
  45. data/jsvc-unix-src/support/apsupport.m4 +155 -0
  46. data/jsvc-unix-src/support/buildconf.sh +33 -0
  47. data/jsvc-unix-src/support/config.guess +1371 -0
  48. data/jsvc-unix-src/support/config.sub +1760 -0
  49. data/jsvc-unix-src/support/install.sh +128 -0
  50. data/jsvc-unix-src/support/mkdist.sh +104 -0
  51. data/lib/trinidad/daemon.rb +31 -0
  52. data/lib/trinidad_init_services.rb +2 -30
  53. data/lib/trinidad_init_services/configuration.rb +91 -14
  54. data/lib/trinidad_init_services/version.rb +5 -0
  55. data/spec/spec_helper.rb +5 -6
  56. data/spec/trinidad_daemon_spec.rb +0 -1
  57. data/spec/trinidad_init_services/configuration_spec.rb +34 -1
  58. data/trinidad_init_services.gemspec +14 -51
  59. metadata +146 -87
  60. data/README +0 -63
  61. data/trinidad-libs/jsvc_linux +0 -0
@@ -0,0 +1,476 @@
1
+ /* Licensed to the Apache Software Foundation (ASF) under one or more
2
+ * contributor license agreements. See the NOTICE file distributed with
3
+ * this work for additional information regarding copyright ownership.
4
+ * The ASF licenses this file to You under the Apache License, Version 2.0
5
+ * (the "License"); you may not use this file except in compliance with
6
+ * the License. You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /* @version $Id: arguments.c 1196468 2011-11-02 06:24:11Z mturk $ */
18
+ #include "jsvc.h"
19
+ #include <limits.h>
20
+ #include <glob.h>
21
+
22
+ /* Return the argument of a command line option */
23
+ static char *optional(int argc, char *argv[], int argi)
24
+ {
25
+
26
+ argi++;
27
+ if (argi >= argc)
28
+ return NULL;
29
+ if (argv[argi] == NULL)
30
+ return NULL;
31
+ if (argv[argi][0] == '-')
32
+ return NULL;
33
+ return strdup(argv[argi]);
34
+ }
35
+
36
+ static char *memstrcat(char *ptr, const char *str, const char *add)
37
+ {
38
+ size_t nl = 1;
39
+ int nas = ptr == NULL;
40
+ if (ptr)
41
+ nl += strlen(ptr);
42
+ if (str)
43
+ nl += strlen(str);
44
+ if (add)
45
+ nl += strlen(add);
46
+ ptr = (char *)realloc(ptr, nl);
47
+ if (ptr) {
48
+ if (nas)
49
+ *ptr = '\0';
50
+ if (str)
51
+ strcat(ptr, str);
52
+ if (add)
53
+ strcat(ptr, add);
54
+ }
55
+ return ptr;
56
+ }
57
+
58
+ static char* eval_ppath(char *strcp, const char *pattern)
59
+ {
60
+ glob_t globbuf;
61
+ char jars[PATH_MAX + 1];
62
+
63
+ if (strlen(pattern) > (sizeof(jars) - 5)) {
64
+ return memstrcat(strcp, pattern, NULL);
65
+ }
66
+ strcpy(jars, pattern);
67
+ strcat(jars, ".jar");
68
+ memset(&globbuf, 0, sizeof(glob_t));
69
+ if (glob(jars, GLOB_ERR, NULL, &globbuf) == 0) {
70
+ size_t n;
71
+ for (n = 0; n < globbuf.gl_pathc - 1; n++) {
72
+ strcp = memstrcat(strcp, globbuf.gl_pathv[n], ":");
73
+ if (strcp == NULL) {
74
+ globfree(&globbuf);
75
+ return NULL;
76
+ }
77
+ }
78
+ strcp = memstrcat(strcp, globbuf.gl_pathv[n], NULL);
79
+ globfree(&globbuf);
80
+ }
81
+ return strcp;
82
+ }
83
+
84
+ #define JAVA_CLASSPATH "-Djava.class.path="
85
+ /**
86
+ * Call glob on each PATH like string path.
87
+ * Glob is called only if the part ends with asterisk in which
88
+ * case asterisk is replaced by *.jar when searching
89
+ */
90
+ static char* eval_cpath(const char *cp)
91
+ {
92
+ char *cpy = memstrcat(NULL, JAVA_CLASSPATH, cp);
93
+ char *gcp = NULL;
94
+ char *pos;
95
+ char *ptr;
96
+
97
+ if (!cpy)
98
+ return NULL;
99
+ ptr = cpy + sizeof(JAVA_CLASSPATH) - 1;;
100
+ while ((pos = strchr(ptr, ':'))) {
101
+ *pos = '\0';
102
+ if (gcp)
103
+ gcp = memstrcat(gcp, ":", NULL);
104
+ else
105
+ gcp = memstrcat(NULL, JAVA_CLASSPATH, NULL);
106
+ if ((pos > ptr) && (*(pos - 1) == '*')) {
107
+ if (!(gcp = eval_ppath(gcp, ptr))) {
108
+ /* Error.
109
+ * Return the original string processed so far.
110
+ */
111
+ return cpy;
112
+ }
113
+ }
114
+ else
115
+ gcp = memstrcat(gcp, ptr, NULL);
116
+ ptr = pos + 1;
117
+ }
118
+ if (*ptr) {
119
+ size_t end = strlen(ptr);
120
+ if (gcp)
121
+ gcp = memstrcat(gcp, ":", NULL);
122
+ else
123
+ gcp = memstrcat(NULL, JAVA_CLASSPATH, NULL);
124
+ if (end > 0 && ptr[end - 1] == '*') {
125
+ /* Last path elemet ends with star
126
+ * Do a globbing.
127
+ */
128
+ gcp = eval_ppath(gcp, ptr);
129
+ }
130
+ else {
131
+ /* Just add the part */
132
+ gcp = memstrcat(gcp, ptr, NULL);
133
+ }
134
+ }
135
+ /* Free the allocated copy */
136
+ if (gcp) {
137
+ free(cpy);
138
+ return gcp;
139
+ }
140
+ else
141
+ return cpy;
142
+ }
143
+
144
+ /* Parse command line arguments */
145
+ static arg_data *parse(int argc, char *argv[])
146
+ {
147
+ arg_data *args = NULL;
148
+ char *temp = NULL;
149
+ char *cmnd = NULL;
150
+ int x = 0;
151
+
152
+ /* Create the default command line arguments */
153
+ args = (arg_data *)malloc(sizeof(arg_data));
154
+ args->pidf = "/var/run/jsvc.pid"; /* The default PID file */
155
+ args->user = NULL; /* No user switching by default */
156
+ args->dtch = true; /* Do detach from parent */
157
+ args->vers = false; /* Don't display version */
158
+ args->help = false; /* Don't display help */
159
+ args->chck = false; /* Don't do a check-only startup */
160
+ args->stop = false; /* Stop a running jsvc */
161
+ args->wait = 0; /* Wait until jsvc has started the JVM */
162
+ args->install = false; /* Don't install as a service */
163
+ args->remove = false; /* Don't remove the installed service */
164
+ args->service = false; /* Don't run as a service */
165
+ args->name = NULL; /* No VM version name */
166
+ args->home = NULL; /* No default JAVA_HOME */
167
+ args->onum = 0; /* Zero arguments, but let's have some room */
168
+ args->clas = NULL; /* No class predefined */
169
+ args->anum = 0; /* Zero class specific arguments but make room*/
170
+ args->outfile = "/dev/null"; /* Swallow by default */
171
+ args->errfile = "/dev/null"; /* Swallow by default */
172
+ args->redirectstdin = true; /* Redirect stdin to /dev/null by default */
173
+ args->procname = "jsvc.exec";
174
+ #ifndef JSVC_UMASK
175
+ args->umask = 0077;
176
+ #else
177
+ args->umask = JSVC_UMASK;
178
+ #endif
179
+
180
+ if (!(args->args = (char **)malloc(argc * sizeof(char *))))
181
+ return NULL;
182
+ if (!(args->opts = (char **)malloc(argc * sizeof(char *))))
183
+ return NULL;
184
+
185
+ /* Set up the command name */
186
+ cmnd = strrchr(argv[0],'/');
187
+ if (cmnd == NULL)
188
+ cmnd = argv[0];
189
+ else
190
+ cmnd++;
191
+ log_prog = strdup(cmnd);
192
+
193
+ /* Iterate thru command line arguments */
194
+ for (x = 1; x < argc; x++) {
195
+
196
+ if (!strcmp(argv[x], "-cp") ||
197
+ !strcmp(argv[x], "-classpath")) {
198
+ temp = optional(argc, argv, x++);
199
+ if (temp == NULL) {
200
+ log_error("Invalid classpath specified");
201
+ return NULL;
202
+ }
203
+ args->opts[args->onum] = eval_cpath(temp);
204
+ if (args->opts[args->onum] == NULL) {
205
+ log_error("Invalid classpath specified");
206
+ return NULL;
207
+ }
208
+ free(temp);
209
+ args->onum++;
210
+
211
+ }
212
+ else if (!strcmp(argv[x], "-jvm")) {
213
+ args->name = optional(argc, argv, x++);
214
+ if (args->name == NULL) {
215
+ log_error("Invalid Java VM name specified");
216
+ return NULL;
217
+ }
218
+ }
219
+ else if (!strcmp(argv[x], "-client")) {
220
+ args->name = strdup("client");
221
+ }
222
+ else if (!strcmp(argv[x], "-server")) {
223
+ args->name = strdup("server");
224
+ }
225
+ else if (!strcmp(argv[x], "-home") ||
226
+ !strcmp(argv[x], "-java-home")) {
227
+ args->home = optional(argc, argv, x++);
228
+ if (args->home == NULL) {
229
+ log_error("Invalid Java Home specified");
230
+ return NULL;
231
+ }
232
+ }
233
+ else if (!strcmp(argv[x], "-user")) {
234
+ args->user = optional(argc, argv, x++);
235
+ if (args->user == NULL) {
236
+ log_error("Invalid user name specified");
237
+ return NULL;
238
+ }
239
+ }
240
+ else if (!strcmp(argv[x], "-version")) {
241
+ args->vers = true;
242
+ args->dtch = false;
243
+ }
244
+ else if (!strcmp(argv[x], "-showversion")) {
245
+ args->vershow = true;
246
+ }
247
+ else if (!strcmp(argv[x], "-?") ||
248
+ !strcmp(argv[x], "-help") ||
249
+ !strcmp(argv[x], "--help")) {
250
+ args->help = true;
251
+ args->dtch = false;
252
+ return args;
253
+ }
254
+ else if (!strcmp(argv[x], "-X")) {
255
+ log_error("Option -X currently unsupported");
256
+ log_error("Please use \"java -X\" to see your extra VM options");
257
+ }
258
+ else if (!strcmp(argv[x], "-debug")) {
259
+ log_debug_flag = true;
260
+ }
261
+ else if (!strcmp(argv[x], "-wait")) {
262
+ temp = optional(argc, argv, x++);
263
+ if (temp)
264
+ args->wait = atoi(temp);
265
+ if (args->wait < 10) {
266
+ log_error("Invalid wait time specified (min=10)");
267
+ return NULL;
268
+ }
269
+ }
270
+ else if (!strcmp(argv[x], "-umask")) {
271
+ temp = optional(argc, argv, x++);
272
+ if (temp == NULL) {
273
+ log_error("Invalid umask specified");
274
+ return NULL;
275
+ }
276
+ args->umask = atoi(temp);
277
+ if (args->umask < 02) {
278
+ log_error("Invalid umask specified (min=02)");
279
+ return NULL;
280
+ }
281
+ }
282
+ else if (!strcmp(argv[x], "-stop")) {
283
+ args->stop = true;
284
+ }
285
+ else if (!strcmp(argv[x], "-check")) {
286
+ args->chck = true;
287
+ args->dtch = false;
288
+ }
289
+ else if (!strcmp(argv[x], "-nodetach")) {
290
+ args->dtch = false;
291
+ }
292
+ else if (!strcmp(argv[x], "-keepstdin")) {
293
+ args->redirectstdin = false;
294
+ }
295
+ else if (!strcmp(argv[x], "-service")) {
296
+ args->service = true;
297
+ }
298
+ else if (!strcmp(argv[x], "-install")) {
299
+ args->install = true;
300
+ }
301
+ else if (!strcmp(argv[x], "-remove")) {
302
+ args->remove = true;
303
+ }
304
+ else if (!strcmp(argv[x], "-pidfile")) {
305
+ args->pidf = optional(argc, argv, x++);
306
+ if (args->pidf == NULL) {
307
+ log_error("Invalid PID file specified");
308
+ return NULL;
309
+ }
310
+ }
311
+ else if (!strcmp(argv[x], "-outfile")) {
312
+ args->outfile = optional(argc, argv, x++);
313
+ if(args->outfile == NULL) {
314
+ log_error("Invalid Output File specified");
315
+ return NULL;
316
+ }
317
+ }
318
+ else if (!strcmp(argv[x], "-errfile")) {
319
+ args->errfile = optional(argc, argv, x++);
320
+ if (args->errfile == NULL) {
321
+ log_error("Invalid Error File specified");
322
+ return NULL;
323
+ }
324
+ }
325
+ else if (!strncmp(argv[x], "-verbose", 8)) {
326
+ args->opts[args->onum++] = strdup(argv[x]);
327
+ }
328
+ else if (!strcmp(argv[x], "-D")) {
329
+ log_error("Parameter -D must be followed by <name>=<value>");
330
+ return NULL;
331
+ }
332
+ else if (!strncmp(argv[x], "-D", 2)) {
333
+ temp = strchr(argv[x], '=');
334
+ if (temp == argv[x] + 2) {
335
+ log_error("A property name must be specified before '='");
336
+ return NULL;
337
+ }
338
+ args->opts[args->onum++] = strdup(argv[x]);
339
+ }
340
+ else if (!strncmp(argv[x], "-X", 2)) {
341
+ args->opts[args->onum++] = strdup(argv[x]);
342
+ }
343
+ else if (!strncmp(argv[x], "-ea", 3)) {
344
+ args->opts[args->onum++] = strdup(argv[x]);
345
+ }
346
+ else if (!strncmp(argv[x], "-enableassertions", 17)) {
347
+ args->opts[args->onum++] = strdup(argv[x]);
348
+ }
349
+ else if (!strncmp(argv[x], "-da", 3)) {
350
+ args->opts[args->onum++] = strdup(argv[x]);
351
+ }
352
+ else if (!strncmp(argv[x], "-disableassertions", 18)) {
353
+ args->opts[args->onum++] = strdup(argv[x]);
354
+ }
355
+ else if (!strcmp(argv[x], "-esa")) {
356
+ args->opts[args->onum++] = strdup(argv[x]);
357
+ }
358
+ else if (!strcmp(argv[x], "-enablesystemassertions")) {
359
+ args->opts[args->onum++] = strdup(argv[x]);
360
+ }
361
+ else if (!strcmp(argv[x], "-dsa")) {
362
+ args->opts[args->onum++] = strdup(argv[x]);
363
+ }
364
+ else if (!strcmp(argv[x], "-disablesystemassertions")) {
365
+ args->opts[args->onum++] = strdup(argv[x]);
366
+ }
367
+ else if (!strcmp(argv[x], "-procname")) {
368
+ args->procname = optional(argc, argv, x++);
369
+ if (args->procname == NULL) {
370
+ log_error("Invalid process name specified");
371
+ return NULL;
372
+ }
373
+ }
374
+ else if (!strncmp(argv[x], "-agentlib:", 10)) {
375
+ args->opts[args->onum++] = strdup(argv[x]);
376
+ }
377
+ else if (!strncmp(argv[x], "-agentpath:", 11)) {
378
+ args->opts[args->onum++] = strdup(argv[x]);
379
+ }
380
+ else if (!strncmp(argv[x], "-javaagent:", 11)) {
381
+ args->opts[args->onum++] = strdup(argv[x]);
382
+ }
383
+ else if (*argv[x] == '-') {
384
+ log_error("Invalid option %s",argv[x]);
385
+ return NULL;
386
+ }
387
+ else {
388
+ args->clas=strdup(argv[x]);
389
+ break;
390
+ }
391
+ }
392
+
393
+ if (args->clas == NULL && args->remove == false) {
394
+ log_error("No class specified");
395
+ return NULL;
396
+ }
397
+
398
+ x++;
399
+ while (x < argc) {
400
+ args->args[args->anum++] = strdup(argv[x++]);
401
+ }
402
+ return args;
403
+ }
404
+ static const char *IsYesNo(bool par)
405
+ {
406
+ switch (par) {
407
+ case false:
408
+ return "No";
409
+ case true:
410
+ return "Yes";
411
+ }
412
+ return "[Error]";
413
+ }
414
+ static const char *IsTrueFalse(bool par)
415
+ {
416
+ switch (par) {
417
+ case false:
418
+ return "False";
419
+ case true:
420
+ return "True";
421
+ }
422
+ return "[Error]";
423
+ }
424
+
425
+ static const char *IsEnabledDisabled(bool par)
426
+ {
427
+ switch (par) {
428
+ case true:
429
+ return "Enabled";
430
+ case false:
431
+ return "Disabled";
432
+ }
433
+ return "[Error]";
434
+ }
435
+
436
+ /* Main entry point: parse command line arguments and dump them */
437
+ arg_data *arguments(int argc, char *argv[])
438
+ {
439
+ arg_data *args = parse(argc,argv);
440
+ int x = 0;
441
+
442
+ if (args == NULL) {
443
+ log_error("Cannot parse command line arguments");
444
+ return NULL;
445
+ }
446
+
447
+ if (log_debug_flag == true) {
448
+ log_debug("+-- DUMPING PARSED COMMAND LINE ARGUMENTS --------------");
449
+ log_debug("| Detach: %s", IsTrueFalse(args->dtch));
450
+ log_debug("| Show Version: %s", IsYesNo(args->vers));
451
+ log_debug("| Show Help: %s", IsYesNo(args->help));
452
+ log_debug("| Check Only: %s", IsEnabledDisabled(args->chck));
453
+ log_debug("| Stop: %s", IsTrueFalse(args->stop));
454
+ log_debug("| Wait: %d", args->wait);
455
+ log_debug("| Run as service: %s", IsYesNo(args->service));
456
+ log_debug("| Install service: %s", IsYesNo(args->install));
457
+ log_debug("| Remove service: %s", IsYesNo(args->remove));
458
+ log_debug("| JVM Name: \"%s\"", PRINT_NULL(args->name));
459
+ log_debug("| Java Home: \"%s\"", PRINT_NULL(args->home));
460
+ log_debug("| PID File: \"%s\"", PRINT_NULL(args->pidf));
461
+ log_debug("| User Name: \"%s\"", PRINT_NULL(args->user));
462
+ log_debug("| Extra Options: %d", args->onum);
463
+ for (x = 0; x < args->onum; x++) {
464
+ log_debug("| \"%s\"", args->opts[x]);
465
+ }
466
+
467
+ log_debug("| Class Invoked: \"%s\"", PRINT_NULL(args->clas));
468
+ log_debug("| Class Arguments: %d", args->anum);
469
+ for (x = 0; x < args->anum; x++) {
470
+ log_debug("| \"%s\"",args->args[x]);
471
+ }
472
+ log_debug("+-------------------------------------------------------");
473
+ }
474
+ return args;
475
+ }
476
+