xref: /unit/src/nxt_application.h (revision 2426:d5e936f09dc0)
1 
2 /*
3  * Copyright (C) Max Romanov
4  * Copyright (C) Valentin V. Bartenev
5  * Copyright (C) NGINX, Inc.
6  */
7 
8 #ifndef _NXT_APPLICATION_H_INCLUDED_
9 #define _NXT_APPLICATION_H_INCLUDED_
10 
11 
12 #include <nxt_conf.h>
13 
14 #include <nxt_unit_typedefs.h>
15 
16 
17 typedef enum {
18     NXT_APP_EXTERNAL,
19     NXT_APP_PYTHON,
20     NXT_APP_PHP,
21     NXT_APP_PERL,
22     NXT_APP_RUBY,
23     NXT_APP_JAVA,
24 
25     NXT_APP_UNKNOWN,
26 } nxt_app_type_t;
27 
28 
29 typedef struct nxt_app_module_s  nxt_app_module_t;
30 typedef nxt_int_t (*nxt_application_setup_t)(nxt_task_t *task,
31     nxt_process_t *process, nxt_common_app_conf_t *conf);
32 
33 
34 typedef struct {
35     nxt_app_type_t            type;
36     u_char                    *version;
37     char                      *file;
38     nxt_app_module_t          *module;
39     nxt_array_t               *mounts;    /* of nxt_fs_mount_t */
40 } nxt_app_lang_module_t;
41 
42 
43 typedef struct {
44     char                       *executable;
45     nxt_conf_value_t           *arguments;
46 } nxt_external_app_conf_t;
47 
48 
49 typedef struct {
50     char                       *home;
51     nxt_conf_value_t           *path;
52     nxt_str_t                  protocol;
53     uint32_t                   threads;
54     uint32_t                   thread_stack_size;
55     nxt_conf_value_t           *targets;
56 } nxt_python_app_conf_t;
57 
58 
59 typedef struct {
60     nxt_conf_value_t           *targets;
61     nxt_conf_value_t           *options;
62 } nxt_php_app_conf_t;
63 
64 
65 typedef struct {
66     char       *script;
67     uint32_t   threads;
68     uint32_t   thread_stack_size;
69 } nxt_perl_app_conf_t;
70 
71 
72 typedef struct {
73     nxt_str_t  script;
74     uint32_t   threads;
75     nxt_str_t  hooks;
76 } nxt_ruby_app_conf_t;
77 
78 
79 typedef struct {
80     nxt_conf_value_t           *classpath;
81     char                       *webapp;
82     nxt_conf_value_t           *options;
83     char                       *unit_jars;
84     uint32_t                   threads;
85     uint32_t                   thread_stack_size;
86 } nxt_java_app_conf_t;
87 
88 
89 struct nxt_common_app_conf_s {
90     nxt_str_t                  name;
91     nxt_str_t                  type;
92     nxt_str_t                  user;
93     nxt_str_t                  group;
94 
95     char                       *stdout_log;
96     char                       *stderr_log;
97 
98     char                       *working_directory;
99     nxt_conf_value_t           *environment;
100 
101     nxt_conf_value_t           *isolation;
102     nxt_conf_value_t           *limits;
103 
104     size_t                     shm_limit;
105     uint32_t                   request_limit;
106 
107     nxt_fd_t                   shared_port_fd;
108     nxt_fd_t                   shared_queue_fd;
109 
110     union {
111         nxt_external_app_conf_t  external;
112         nxt_python_app_conf_t    python;
113         nxt_php_app_conf_t       php;
114         nxt_perl_app_conf_t      perl;
115         nxt_ruby_app_conf_t      ruby;
116         nxt_java_app_conf_t      java;
117     } u;
118 
119     nxt_conf_value_t           *self;
120 };
121 
122 
123 struct nxt_app_module_s {
124     size_t                     compat_length;
125     uint32_t                   *compat;
126 
127     nxt_str_t                  type;
128     const char                 *version;
129 
130     const nxt_fs_mount_t       *mounts;
131     nxt_uint_t                 nmounts;
132 
133     nxt_application_setup_t    setup;
134     nxt_process_start_t        start;
135 };
136 
137 
138 nxt_app_lang_module_t *nxt_app_lang_module(nxt_runtime_t *rt, nxt_str_t *name);
139 nxt_app_type_t nxt_app_parse_type(u_char *p, size_t length);
140 
141 NXT_EXPORT extern nxt_str_t  nxt_server;
142 extern nxt_app_module_t      nxt_external_module;
143 
144 NXT_EXPORT nxt_int_t nxt_unit_default_init(nxt_task_t *task,
145     nxt_unit_init_t *init, nxt_common_app_conf_t *conf);
146 
147 NXT_EXPORT nxt_int_t nxt_app_set_logs(void);
148 
149 #endif /* _NXT_APPLICATION_H_INCLIDED_ */
150