diff --git a/src/tarantool.cc b/src/tarantool.cc index f24100800e6ba5b2b0caeb789357608f9b625472..2343bf967ec428d5960945fa8c42e38d47b2d283 100644 --- a/src/tarantool.cc +++ b/src/tarantool.cc @@ -443,6 +443,21 @@ sig_fatal_cb(int signo) abort(); } +/** + * This SIGTERM handler is only used before the main event loop started to + * cleanup server pid file. The handler is replaced by ev_signal after the boot. + * @sa signal_start + */ +static void +sig_term_cb(int signo) +{ + (void) signo; + /* unlink pidfile. */ + if (cfg.pid_file != NULL) + unlink(cfg.pid_file); + + _exit(EXIT_SUCCESS); +} static void signal_free(void) @@ -511,6 +526,12 @@ signal_init(void) exit(EX_OSERR); } + sa.sa_handler = sig_term_cb; + if (sigaction(SIGTERM, &sa, 0) == -1) { + say_syserror("sigaction"); + exit(EX_OSERR); + } + ev_signal_init(&ev_sigs[0], sig_snapshot, SIGUSR1); ev_signal_init(&ev_sigs[1], signal_cb, SIGINT); ev_signal_init(&ev_sigs[2], signal_cb, SIGTERM); @@ -599,7 +620,6 @@ tarantool_lua_free() tarantool_L = NULL; } - void tarantool_free(void) { @@ -619,8 +639,8 @@ tarantool_free(void) gopt_free(main_opt); free_proc_title(main_argc, main_argv); - /* unlink pidfile but not in replication process. */ - if ((cfg.pid_file != NULL) && (master_pid == getpid())) + /* unlink pidfile. */ + if (cfg.pid_file != NULL) unlink(cfg.pid_file); destroy_tarantool_cfg(&cfg);