xref: /unit/src/nxt_application.h (revision 2678:f6fe06c2522e)
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     NXT_APP_WASM,
25     NXT_APP_WASM_WC,
26 
27     NXT_APP_UNKNOWN,
28 } nxt_app_type_t;
29 
30 
31 typedef struct nxt_app_module_s  nxt_app_module_t;
32 typedef nxt_int_t (*nxt_application_setup_t)(nxt_task_t *task,
33     nxt_process_t *process, nxt_common_app_conf_t *conf);
34 
35 
36 typedef struct {
37     nxt_app_type_t            type;
38     u_char                    *version;
39     char                      *file;
40     nxt_app_module_t          *module;
41     nxt_array_t               *mounts;    /* of nxt_fs_mount_t */
42 } nxt_app_lang_module_t;
43 
44 
45 typedef struct {
46     char                       *executable;
47     nxt_conf_value_t           *arguments;
48 } nxt_external_app_conf_t;
49 
50 
51 typedef struct {
52     char                       *home;
53     nxt_conf_value_t           *path;
54     nxt_str_t                  protocol;
55     uint32_t                   threads;
56     uint32_t                   thread_stack_size;
57     nxt_conf_value_t           *targets;
58 } nxt_python_app_conf_t;
59 
60 
61 typedef struct {
62     nxt_conf_value_t           *targets;
63     nxt_conf_value_t           *options;
64 } nxt_php_app_conf_t;
65 
66 
67 typedef struct {
68     char       *script;
69     uint32_t   threads;
70     uint32_t   thread_stack_size;
71 } nxt_perl_app_conf_t;
72 
73 
74 typedef struct {
75     nxt_str_t  script;
76     uint32_t   threads;
77     nxt_str_t  hooks;
78 } nxt_ruby_app_conf_t;
79 
80 
81 typedef struct {
82     nxt_conf_value_t           *classpath;
83     char                       *webapp;
84     nxt_conf_value_t           *options;
85     char                       *unit_jars;
86     uint32_t                   threads;
87     uint32_t                   thread_stack_size;
88 } nxt_java_app_conf_t;
89 
90 
91 typedef struct {
92     const char        *module;
93 
94     const char        *request_handler;
95     const char        *malloc_handler;
96     const char        *free_handler;
97 
98     const char        *module_init_handler;
99     const char        *module_end_handler;
100     const char        *request_init_handler;
101     const char        *request_end_handler;
102     const char        *response_end_handler;
103 
104     nxt_conf_value_t  *access;
105 } nxt_wasm_app_conf_t;
106 
107 
108 typedef struct {
109     const char        *component;
110 
111     nxt_conf_value_t  *access;
112 } nxt_wasm_wc_app_conf_t;
113 
114 
115 struct nxt_common_app_conf_s {
116     nxt_str_t                  name;
117     nxt_str_t                  type;
118     nxt_str_t                  user;
119     nxt_str_t                  group;
120 
121     char                       *stdout_log;
122     char                       *stderr_log;
123 
124     char                       *working_directory;
125     nxt_conf_value_t           *environment;
126 
127     nxt_conf_value_t           *isolation;
128     nxt_conf_value_t           *limits;
129 
130     size_t                     shm_limit;
131     uint32_t                   request_limit;
132 
133     nxt_fd_t                   shared_port_fd;
134     nxt_fd_t                   shared_queue_fd;
135 
136     union {
137         nxt_external_app_conf_t  external;
138         nxt_python_app_conf_t    python;
139         nxt_php_app_conf_t       php;
140         nxt_perl_app_conf_t      perl;
141         nxt_ruby_app_conf_t      ruby;
142         nxt_java_app_conf_t      java;
143         nxt_wasm_app_conf_t      wasm;
144         nxt_wasm_wc_app_conf_t   wasm_wc;
145     } u;
146 
147     nxt_conf_value_t           *self;
148 };
149 
150 
151 struct nxt_app_module_s {
152     size_t                     compat_length;
153     uint32_t                   *compat;
154 
155     nxt_str_t                  type;
156     const char                 *version;
157 
158     const nxt_fs_mount_t       *mounts;
159     nxt_uint_t                 nmounts;
160 
161     nxt_application_setup_t    setup;
162     nxt_process_start_t        start;
163 };
164 
165 
166 nxt_app_lang_module_t *nxt_app_lang_module(nxt_runtime_t *rt, nxt_str_t *name);
167 nxt_app_type_t nxt_app_parse_type(u_char *p, size_t length);
168 
169 NXT_EXPORT extern nxt_str_t  nxt_server;
170 extern nxt_app_module_t      nxt_external_module;
171 
172 NXT_EXPORT nxt_int_t nxt_unit_default_init(nxt_task_t *task,
173     nxt_unit_init_t *init, nxt_common_app_conf_t *conf);
174 
175 NXT_EXPORT nxt_int_t nxt_app_set_logs(void);
176 
177 #endif /* _NXT_APPLICATION_H_INCLIDED_ */
178