summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/nxt_application.c53
-rw-r--r--src/nxt_application.h4
-rw-r--r--src/nxt_conf_validation.c6
-rw-r--r--src/nxt_main_process.c12
-rw-r--r--src/nxt_process.c6
5 files changed, 81 insertions, 0 deletions
diff --git a/src/nxt_application.c b/src/nxt_application.c
index 786c768b..ffa8eb53 100644
--- a/src/nxt_application.c
+++ b/src/nxt_application.c
@@ -933,6 +933,59 @@ nxt_app_set_environment(nxt_conf_value_t *environment)
}
+nxt_int_t
+nxt_app_set_logs(void)
+{
+ nxt_int_t ret;
+ nxt_file_t file;
+ nxt_task_t *task;
+ nxt_thread_t *thr;
+ nxt_process_t *process;
+ nxt_runtime_t *rt;
+ nxt_common_app_conf_t *app_conf;
+
+ thr = nxt_thread();
+
+ task = thr->task;
+
+ rt = task->thread->runtime;
+ if (!rt->daemon) {
+ return NXT_OK;
+ }
+
+ process = rt->port_by_type[NXT_PROCESS_PROTOTYPE]->process;
+ app_conf = process->data.app;
+
+ if (app_conf->stdout_log != NULL) {
+ nxt_memzero(&file, sizeof(nxt_file_t));
+ file.log_level = 1;
+ file.name = (u_char *) app_conf->stdout_log;
+ ret = nxt_file_open(task, &file, O_WRONLY | O_APPEND, O_CREAT, 0666);
+ if (ret == NXT_ERROR) {
+ return NXT_ERROR;
+ }
+
+ nxt_file_stdout(&file);
+ nxt_file_close(task, &file);
+ }
+
+ if (app_conf->stderr_log != NULL) {
+ nxt_memzero(&file, sizeof(nxt_file_t));
+ file.log_level = 1;
+ file.name = (u_char *) app_conf->stderr_log;
+ ret = nxt_file_open(task, &file, O_WRONLY | O_APPEND, O_CREAT, 0666);
+ if (ret == NXT_ERROR) {
+ return NXT_ERROR;
+ }
+
+ nxt_file_stderr(&file);
+ nxt_file_close(task, &file);
+ }
+
+ return NXT_OK;
+}
+
+
static u_char *
nxt_cstr_dup(nxt_mp_t *mp, u_char *dst, u_char *src)
{
diff --git a/src/nxt_application.h b/src/nxt_application.h
index 4d624448..2675e6a0 100644
--- a/src/nxt_application.h
+++ b/src/nxt_application.h
@@ -92,6 +92,9 @@ struct nxt_common_app_conf_s {
nxt_str_t user;
nxt_str_t group;
+ char *stdout_log;
+ char *stderr_log;
+
char *working_directory;
nxt_conf_value_t *environment;
@@ -141,5 +144,6 @@ extern nxt_app_module_t nxt_external_module;
NXT_EXPORT nxt_int_t nxt_unit_default_init(nxt_task_t *task,
nxt_unit_init_t *init, nxt_common_app_conf_t *conf);
+NXT_EXPORT nxt_int_t nxt_app_set_logs(void);
#endif /* _NXT_APPLICATION_H_INCLIDED_ */
diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c
index 9169bcc9..6d798a81 100644
--- a/src/nxt_conf_validation.c
+++ b/src/nxt_conf_validation.c
@@ -1047,6 +1047,12 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_common_members[] = {
.type = NXT_CONF_VLDT_OBJECT,
.validator = nxt_conf_vldt_isolation,
.u.members = nxt_conf_vldt_app_isolation_members,
+ }, {
+ .name = nxt_string("stdout"),
+ .type = NXT_CONF_VLDT_STRING,
+ }, {
+ .name = nxt_string("stderr"),
+ .type = NXT_CONF_VLDT_STRING,
},
NXT_CONF_VLDT_END
diff --git a/src/nxt_main_process.c b/src/nxt_main_process.c
index db1cfcb9..ae62aff4 100644
--- a/src/nxt_main_process.c
+++ b/src/nxt_main_process.c
@@ -121,6 +121,18 @@ static nxt_conf_map_t nxt_common_app_conf[] = {
},
{
+ nxt_string("stdout"),
+ NXT_CONF_MAP_CSTRZ,
+ offsetof(nxt_common_app_conf_t, stdout_log),
+ },
+
+ {
+ nxt_string("stderr"),
+ NXT_CONF_MAP_CSTRZ,
+ offsetof(nxt_common_app_conf_t, stderr_log),
+ },
+
+ {
nxt_string("working_directory"),
NXT_CONF_MAP_CSTRZ,
offsetof(nxt_common_app_conf_t, working_directory),
diff --git a/src/nxt_process.c b/src/nxt_process.c
index c7f10769..ce2de774 100644
--- a/src/nxt_process.c
+++ b/src/nxt_process.c
@@ -5,6 +5,8 @@
*/
#include <nxt_main.h>
+
+#include <nxt_application.h>
#include <nxt_cgroup.h>
#if (NXT_HAVE_LINUX_NS)
@@ -651,6 +653,10 @@ nxt_process_setup(nxt_task_t *task, nxt_process_t *process)
thread = task->thread;
rt = thread->runtime;
+ if (process->parent_port == rt->port_by_type[NXT_PROCESS_PROTOTYPE]) {
+ nxt_app_set_logs();
+ }
+
nxt_random_init(&thread->random);
rt->type = init->type;