trinidad_init_services 1.1.3 → 1.1.4

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.
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,94 @@
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.h 1196265 2011-11-01 20:43:52Z mturk $ */
18
+ #ifndef __JSVC_ARGUMENTS_H__
19
+ #define __JSVC_ARGUMENTS_H__
20
+
21
+ #ifdef __cplusplus
22
+ extern "C"
23
+ {
24
+ #endif
25
+
26
+ /**
27
+ * The structure holding all parsed command line options.
28
+ */
29
+ typedef struct {
30
+ /** The name of the PID file. */
31
+ char *pidf;
32
+ /** The name of the user. */
33
+ char *user;
34
+ /** The name of the JVM to use. */
35
+ char *name;
36
+ /** The JDK or JRE installation path (JAVA_HOME). */
37
+ char *home;
38
+ /** Options used to invoke the JVM. */
39
+ char **opts;
40
+ /** Number of JVM options. */
41
+ int onum;
42
+ /** The name of the class to invoke. */
43
+ char *clas;
44
+ /** Command line arguments to the class. */
45
+ char **args;
46
+ /** Number of class command line arguments. */
47
+ int anum;
48
+ /** Wether to detach from parent process or not. */
49
+ bool dtch;
50
+ /** Wether to print the VM version number or not. */
51
+ bool vers;
52
+ /** Show the VM version and continue. */
53
+ bool vershow;
54
+ /** Wether to display the help page or not. */
55
+ bool help;
56
+ /** Only check environment without running the service. */
57
+ bool chck;
58
+ /** Stop running jsvc */
59
+ bool stop;
60
+ /** number of seconds to until service started */
61
+ int wait;
62
+ /** Install as a service (win32) */
63
+ bool install;
64
+ /** Remove when installed as a service (win32) */
65
+ bool remove;
66
+ /** Run as a service (win32) */
67
+ bool service;
68
+ /** Destination for stdout */
69
+ char *outfile;
70
+ /** Destination for stderr */
71
+ char *errfile;
72
+ /** Program name **/
73
+ char *procname;
74
+ /** Whether to redirect stdin to /dev/null or not. Defaults to true **/
75
+ bool redirectstdin;
76
+ /** What umask to use **/
77
+ int umask;
78
+ } arg_data;
79
+
80
+ /**
81
+ * Parse command line arguments.
82
+ *
83
+ * @param argc The number of command line arguments.
84
+ * @param argv Pointers to the different arguments.
85
+ * @return A pointer to a arg_data structure containing the parsed command
86
+ * line arguments, or NULL if an error was detected.
87
+ */
88
+ arg_data *arguments(int argc, char *argv[]);
89
+
90
+ #ifdef __cplusplus
91
+ }
92
+ #endif
93
+ #endif /* ifndef __JSVC_ARGUMENTS_H__ */
94
+
@@ -0,0 +1,87 @@
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: debug.c 1198399 2011-11-06 16:20:44Z mturk $ */
18
+ #include "jsvc.h"
19
+ #include <sys/types.h>
20
+ #include <unistd.h>
21
+ #include <time.h>
22
+
23
+ /* Wether debug is enabled or not */
24
+ bool log_debug_flag = false;
25
+
26
+ /* Wether SYSLOG logging (for stderr) is enable or not. */
27
+ bool log_stderr_syslog_flag = false;
28
+
29
+ /* Wether SYSLOG logging (for stdout) is enable or not. */
30
+ bool log_stdout_syslog_flag = false;
31
+
32
+ /* The name of the jsvc binary. */
33
+ char *log_prog = "jsvc";
34
+
35
+ /* Dump a debug trace message to stderr */
36
+ void log_debug(const char *fmt, ...)
37
+ {
38
+ va_list ap;
39
+ time_t now;
40
+ struct tm *nowtm;
41
+ char buff[80];
42
+
43
+ if (log_debug_flag == false)
44
+ return;
45
+ if (fmt == NULL)
46
+ return;
47
+
48
+ now = time(NULL);
49
+ nowtm = localtime(&now);
50
+ strftime(buff, sizeof(buff), "%Y-%m-%d %T", nowtm);
51
+ va_start(ap, fmt);
52
+ if (log_stderr_syslog_flag)
53
+ fprintf(stderr, "%s %d %s debug: ", buff, getpid(), log_prog);
54
+ #if defined(DEBUG) || defined(_DEBUG)
55
+ else
56
+ fprintf(stderr, "[debug] %s %d ", buff, getpid());
57
+ #endif
58
+ vfprintf(stderr, fmt, ap);
59
+ fprintf(stderr, "\n");
60
+ fflush(stderr);
61
+ va_end(ap);
62
+ }
63
+
64
+ /* Dump an error message to stderr */
65
+ void log_error(const char *fmt, ...)
66
+ {
67
+ va_list ap;
68
+ time_t now;
69
+ struct tm *nowtm;
70
+ char buff[80];
71
+
72
+ if (fmt == NULL)
73
+ return;
74
+
75
+ va_start(ap, fmt);
76
+ if (log_stderr_syslog_flag) {
77
+ now = time(NULL);
78
+ nowtm = localtime(&now);
79
+ strftime(buff, sizeof(buff), "%Y-%m-%d %T", nowtm);
80
+ fprintf(stderr, "%s %d %s error: ", buff, getpid(), log_prog);
81
+ }
82
+ vfprintf(stderr, fmt, ap);
83
+ fprintf(stderr, "\n");
84
+ fflush(stderr);
85
+ va_end(ap);
86
+ }
87
+
@@ -0,0 +1,65 @@
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: debug.h 982549 2010-08-05 11:43:42Z mturk $ */
18
+ #ifndef __JSVC_DEBUG_H__
19
+ #define __JSVC_DEBUG_H__
20
+
21
+ #ifdef __cplusplus
22
+ extern "C" {
23
+ #endif
24
+ /**
25
+ * Wether debugging is enabled or not.
26
+ */
27
+ extern bool log_debug_flag;
28
+
29
+ /* Wether SYSLOG logging (for stderr) is enable or not. */
30
+ extern bool log_stderr_syslog_flag;
31
+
32
+ /* Wether SYSLOG logging (for stdout) is enable or not. */
33
+ extern bool log_stdout_syslog_flag;
34
+
35
+ /**
36
+ * The name of the jsvc binary.
37
+ */
38
+ extern char *log_prog;
39
+
40
+ /**
41
+ * Helper macro to avoid NPEs in printf.
42
+ */
43
+ #define PRINT_NULL(x) ((x) == NULL ? "null" : (x))
44
+
45
+ /**
46
+ * Dump a debug message.
47
+ *
48
+ * @param fmt The printf style message format.
49
+ * @param ... Any optional parameter for the message.
50
+ */
51
+ void log_debug(const char *fmt, ...);
52
+
53
+ /**
54
+ * Dump an error message.
55
+ *
56
+ * @param fmt The printf style message format.
57
+ * @param ... Any optional parameter for the message.
58
+ */
59
+ void log_error(const char *fmt, ...);
60
+
61
+ #ifdef __cplusplus
62
+ }
63
+ #endif
64
+ #endif /* ifndef __JSVC_DEBUG_H__ */
65
+
@@ -0,0 +1,62 @@
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: dso-dlfcn.c 921765 2010-03-11 10:03:32Z mturk $ */
18
+ #include "jsvc.h"
19
+
20
+ #ifdef DSO_DLFCN
21
+ #include <dlfcn.h>
22
+ #ifdef OS_LINUX
23
+ bool ld_library_path_set = false;
24
+ #endif /* ifdef OS_LINUX */
25
+
26
+ /* Initialize all DSO stuff */
27
+ bool dso_init(void)
28
+ {
29
+ return true;
30
+ }
31
+
32
+ /* Attempt to link a library from a specified filename */
33
+ dso_handle dso_link(const char *path)
34
+ {
35
+ log_debug("Attemtping to load library %s", path);
36
+
37
+ return ((void *)dlopen(path, RTLD_GLOBAL | RTLD_NOW));
38
+ }
39
+
40
+ /* Attempt to unload a library */
41
+ bool dso_unlink(dso_handle libr)
42
+ {
43
+ if (dlclose(libr) == 0)
44
+ return true;
45
+ else
46
+ return false;
47
+ }
48
+
49
+ /* Get the address for a specifed symbol */
50
+ void *dso_symbol(dso_handle hdl, const char *nam)
51
+ {
52
+ return dlsym(hdl, nam);
53
+ }
54
+
55
+ /* Return the error message from dlopen */
56
+ char *dso_error(void)
57
+ {
58
+ return (dlerror());
59
+ }
60
+
61
+ #endif /* ifdef DSO_DLFCN */
62
+
@@ -0,0 +1,153 @@
1
+ /*
2
+ Licensed to the Apache Software Foundation (ASF) under one or more
3
+ contributor license agreements. See the NOTICE file distributed with
4
+ this work for additional information regarding copyright ownership.
5
+ The ASF licenses this file to You under the Apache License, Version 2.0
6
+ (the "License"); you may not use this file except in compliance with
7
+ the License. You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ */
17
+ /* @version $Id: dso-dyld.c 921765 2010-03-11 10:03:32Z mturk $ */
18
+ #include "jsvc.h"
19
+
20
+ #ifdef DSO_DYLD
21
+
22
+ #include <mach-o/dyld.h>
23
+
24
+ #ifdef __bool_true_false_are_defined
25
+ /* We define these differently than stdbool.h, so ignore the defs there */
26
+ #undef bool
27
+ #undef true
28
+ #undef false
29
+ #endif
30
+
31
+
32
+ /* Print an error message and abort all if a specified symbol wasn't found */
33
+ static void nosymbol(const char *s)
34
+ {
35
+ log_error("Cannot find symbol '%s' in library", s);
36
+ abort();
37
+ }
38
+
39
+ /* We found two symbols for the same name in two different modules */
40
+ static NSModule multiple(NSSymbol s, NSModule om, NSModule nm)
41
+ {
42
+ NSModule ret = nm;
43
+
44
+ log_debug("Symbol \"%s\" found in modules \"%s\" and \"%s\" (using %s)",
45
+ NSNameOfSymbol(s), NSNameOfModule(om), NSNameOfModule(nm),
46
+ NSNameOfModule(ret));
47
+
48
+ return (ret);
49
+ }
50
+
51
+ /* We got an error while linking a module, and if it's not a warning we have
52
+ to abort the whole program */
53
+ static void linkedit(NSLinkEditErrors category, int number, const char *file,
54
+ const char *message)
55
+ {
56
+ log_error("Errors during link edit of file \"%s\" (error=%d): %s", file,
57
+ number, message);
58
+ /* Check if this error was only a warning */
59
+ if (category != NSLinkEditWarningError) {
60
+ log_error("Cannot continue");
61
+ abort();
62
+ }
63
+ }
64
+
65
+ /* Initialize all DSO stuff */
66
+ bool dso_init()
67
+ {
68
+ NSLinkEditErrorHandlers h;
69
+
70
+ h.undefined = nosymbol;
71
+ h.multiple = multiple;
72
+ h.linkEdit = linkedit;
73
+
74
+ NSInstallLinkEditErrorHandlers(&h);
75
+ return (true);
76
+ }
77
+
78
+ /* Attempt to link a library from a specified filename */
79
+ dso_handle dso_link(const char *path)
80
+ {
81
+ /* We need to load the library publically as NSModuleFileImage is not
82
+ yet implemented (at least for non MH_BUNDLE libraries */
83
+ if (NSAddLibrary(path) != TRUE)
84
+ return (NULL);
85
+ /* We need to return a non-null value, even if it has no meaning. One day
86
+ this whole crap will be fixed */
87
+ return ((void *)!NULL);
88
+ }
89
+
90
+ /* Attempt to unload a library */
91
+ bool dso_unlink(dso_handle libr)
92
+ {
93
+ /* Check the handle */
94
+ if (libr == NULL) {
95
+ log_error("Attempting to unload a module without handle");
96
+ return (false);
97
+ }
98
+
99
+ /* We don't have a module, so, we don't really have to do anything */
100
+ return (true);
101
+ }
102
+
103
+ /* Get the address for a specifed symbol */
104
+ void *dso_symbol(dso_handle hdl, const char *nam)
105
+ {
106
+ NSSymbol sym = NULL;
107
+ NSModule mod = NULL;
108
+ char *und = NULL;
109
+ void *add = NULL;
110
+ int x = 0;
111
+
112
+ /* Check parameters */
113
+ if (hdl == NULL) {
114
+ log_error("Invalid library handler specified");
115
+ return (NULL);
116
+ }
117
+
118
+ if (nam == NULL) {
119
+ log_error("Invalid symbol name specified");
120
+ return (NULL);
121
+ }
122
+
123
+ /* Process the correct name (add a _ before the name) */
124
+ while (nam[x] != '\0')
125
+ x++;
126
+ und = (char *)malloc(sizeof(char) * (x + 2));
127
+ while (x >= 0)
128
+ und[x + 1] = nam[x--];
129
+ und[0] = '_';
130
+
131
+ /* Find the symbol */
132
+ sym = NSLookupAndBindSymbol(und);
133
+ free(und);
134
+ if (sym == NULL)
135
+ return (NULL);
136
+
137
+ /* Dump some debugging output since this part is shaky */
138
+ mod = NSModuleForSymbol(sym);
139
+ add = NSAddressOfSymbol(sym);
140
+ log_debug("Symbol \"%s\" found in module \"%s\" at address \"0x%08X\"",
141
+ NSNameOfSymbol(sym), NSNameOfModule(mod), add);
142
+
143
+ /* We want to return the address of the symbol */
144
+ return (add);
145
+ }
146
+
147
+ /* Return the error message from dlopen: Well we already print it */
148
+ char *dso_error()
149
+ {
150
+ return ("no additional message");
151
+ }
152
+
153
+ #endif /* ifdef DSO_DYLD */