Restart the server, executing the same executable that started this * instance, with the same arguments and configuration file. * * The function is designed to directly call execve() so that the new * server instance will retain the PID of the previous one. * * The list of flags, that may be bitwise ORed together, alter the * behavior of this function: * * RESTART_SERVER_NONE
| 2795 | * On success the function does not return, because the process turns into |
| 2796 | * a different process. On error C_ERR is returned. */ |
| 2797 | int restartServer(int flags, mstime_t delay) { |
| 2798 | int j; |
| 2799 | |
| 2800 | /* Check if we still have accesses to the executable that started this |
| 2801 | * server instance. */ |
| 2802 | if (access(server.executable,X_OK) == -1) { |
| 2803 | serverLog(LL_WARNING,"Can't restart: this process has no " |
| 2804 | "permissions to execute %s", server.executable); |
| 2805 | return C_ERR; |
| 2806 | } |
| 2807 | |
| 2808 | /* Config rewriting. */ |
| 2809 | if (flags & RESTART_SERVER_CONFIG_REWRITE && |
| 2810 | server.configfile && |
| 2811 | rewriteConfig(server.configfile, 0) == -1) |
| 2812 | { |
| 2813 | serverLog(LL_WARNING,"Can't restart: configuration rewrite process " |
| 2814 | "failed"); |
| 2815 | return C_ERR; |
| 2816 | } |
| 2817 | |
| 2818 | /* Perform a proper shutdown. */ |
| 2819 | if (flags & RESTART_SERVER_GRACEFULLY && |
| 2820 | prepareForShutdown(SHUTDOWN_NOFLAGS) != C_OK) |
| 2821 | { |
| 2822 | serverLog(LL_WARNING,"Can't restart: error preparing for shutdown"); |
| 2823 | return C_ERR; |
| 2824 | } |
| 2825 | |
| 2826 | /* Close all file descriptors, with the exception of stdin, stdout, strerr |
| 2827 | * which are useful if we restart a Redis server which is not daemonized. */ |
| 2828 | for (j = 3; j < (int)server.maxclients + 1024; j++) { |
| 2829 | /* Test the descriptor validity before closing it, otherwise |
| 2830 | * Valgrind issues a warning on close(). */ |
| 2831 | if (fcntl(j,F_GETFD) != -1) close(j); |
| 2832 | } |
| 2833 | |
| 2834 | /* Execute the server with the original command line. */ |
| 2835 | if (delay) usleep(delay*1000); |
| 2836 | zfree(server.exec_argv[0]); |
| 2837 | server.exec_argv[0] = zstrdup(server.executable); |
| 2838 | execve(server.executable,server.exec_argv,environ); |
| 2839 | |
| 2840 | /* If an error occurred here, there is nothing we can do, but exit. */ |
| 2841 | _exit(1); |
| 2842 | |
| 2843 | return C_ERR; /* Never reached. */ |
| 2844 | } |
| 2845 | |
| 2846 | static void readOOMScoreAdj(void) { |
| 2847 | #ifdef HAVE_PROC_OOM_SCORE_ADJ |
no test coverage detected