bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2010-2018 Dovecot authors, see the included COPYING file */
169b1488b6eea7a968021afa4f929b2e26d75d98Timo Sirainenstatic bool pid_file_read(const char *path, pid_t *pid_r)
169b1488b6eea7a968021afa4f929b2e26d75d98Timo Sirainen unsigned int i;
169b1488b6eea7a968021afa4f929b2e26d75d98Timo Sirainen pidfile_path = t_strconcat(doveadm_settings->base_dir,
169b1488b6eea7a968021afa4f929b2e26d75d98Timo Sirainen i_fatal("Dovecot is not running (read from %s)", pidfile_path);
169b1488b6eea7a968021afa4f929b2e26d75d98Timo Sirainen i_fatal("kill(%s, %d) failed: %m", dec2str(pid), signo);
169b1488b6eea7a968021afa4f929b2e26d75d98Timo Sirainen /* wait for a while for the process to die */
169b1488b6eea7a968021afa4f929b2e26d75d98Timo Sirainen for (i = 0; i < 30; i++) {
169b1488b6eea7a968021afa4f929b2e26d75d98Timo Sirainenstatic void cmd_stop(int argc ATTR_UNUSED, char *argv[] ATTR_UNUSED)
169b1488b6eea7a968021afa4f929b2e26d75d98Timo Sirainenstatic void cmd_reload(int argc ATTR_UNUSED, char *argv[] ATTR_UNUSED)
7237f2f0a577413e12662228ee2039425fd2f5b0Timo Sirainenstatic struct istream *master_service_send_cmd(const char *cmd)
c7713320cd35e77543f1bdc7229988a160dae322Timo Sirainen path = t_strconcat(doveadm_settings->base_dir, "/master", NULL);
c7713320cd35e77543f1bdc7229988a160dae322Timo Sirainen i_fatal("net_connect_unix(%s) failed: %m", path);
7237f2f0a577413e12662228ee2039425fd2f5b0Timo Sirainen t_strdup_printf("VERSION\tmaster-client\t1\t0\n%s\n", cmd);
7237f2f0a577413e12662228ee2039425fd2f5b0Timo Sirainen return i_stream_create_fd_autoclose(&fd, IO_BLOCK_SIZE);
27bb267255b36d34c638c34a1ade611962f00772Timo Sirainenstatic struct istream *
27bb267255b36d34c638c34a1ade611962f00772Timo Sirainenmaster_service_send_cmd_with_args(const char *cmd, const char *const *args)
27bb267255b36d34c638c34a1ade611962f00772Timo Sirainen for (unsigned int i = 0; args[i] != NULL; i++) {
de41dbb482990a4be10ca9033cf881a850ccdc50Timo Sirainenstatic void cmd_service_stop(struct doveadm_cmd_context *cctx)
de41dbb482990a4be10ca9033cf881a850ccdc50Timo Sirainen if (!doveadm_cmd_param_array(cctx, "service", &services))
27bb267255b36d34c638c34a1ade611962f00772Timo Sirainen master_service_send_cmd_with_args("STOP", services);
c7713320cd35e77543f1bdc7229988a160dae322Timo Sirainen (line = i_stream_read_next_line(input)) == NULL) {
7237f2f0a577413e12662228ee2039425fd2f5b0Timo Sirainen i_error("read(%s) failed: %s", i_stream_get_name(input),
eba7f36feec8d02c4c394e55ff4effd47e33d311Timo Sirainenstatic void cmd_service_status(struct doveadm_cmd_context *cctx)
eba7f36feec8d02c4c394e55ff4effd47e33d311Timo Sirainen if (!doveadm_cmd_param_array(cctx, "service", &services))
eba7f36feec8d02c4c394e55ff4effd47e33d311Timo Sirainen struct istream *input = master_service_send_cmd("SERVICE-STATUS");
eba7f36feec8d02c4c394e55ff4effd47e33d311Timo Sirainen doveadm_print_header_simple("exit_failure_last");
eba7f36feec8d02c4c394e55ff4effd47e33d311Timo Sirainen doveadm_print_header_simple("exit_failures_in_sec");
eba7f36feec8d02c4c394e55ff4effd47e33d311Timo Sirainen doveadm_print_header_simple("last_drop_warning");
eba7f36feec8d02c4c394e55ff4effd47e33d311Timo Sirainen doveadm_print_header_simple("listen_pending");
eba7f36feec8d02c4c394e55ff4effd47e33d311Timo Sirainen while ((line = i_stream_read_next_line(input)) != NULL) {
eba7f36feec8d02c4c394e55ff4effd47e33d311Timo Sirainen const char *const *args = t_strsplit_tabescaped(line);
77a41c18e6c37ea9d88a300173672746e29fe61bTimo Sirainen for (unsigned int i = 0; i < 12; i++)
eba7f36feec8d02c4c394e55ff4effd47e33d311Timo Sirainen i_error("read(%s) failed: %s", i_stream_get_name(input),
d78f1ac9dc0f3e6c64cebe9ee331ec6b3c160e89Timo Sirainenstatic void cmd_process_status(struct doveadm_cmd_context *cctx)
d78f1ac9dc0f3e6c64cebe9ee331ec6b3c160e89Timo Sirainen if (!doveadm_cmd_param_array(cctx, "service", &services))
d78f1ac9dc0f3e6c64cebe9ee331ec6b3c160e89Timo Sirainen master_service_send_cmd_with_args("PROCESS-STATUS", services);
d78f1ac9dc0f3e6c64cebe9ee331ec6b3c160e89Timo Sirainen doveadm_print_header_simple("available_count");
d78f1ac9dc0f3e6c64cebe9ee331ec6b3c160e89Timo Sirainen doveadm_print_header_simple("last_status_update");
d78f1ac9dc0f3e6c64cebe9ee331ec6b3c160e89Timo Sirainen doveadm_print_header_simple("last_kill_sent");
d78f1ac9dc0f3e6c64cebe9ee331ec6b3c160e89Timo Sirainen while ((line = i_stream_read_next_line(input)) != NULL) {
d78f1ac9dc0f3e6c64cebe9ee331ec6b3c160e89Timo Sirainen const char *const *args = t_strsplit_tabescaped(line);
d78f1ac9dc0f3e6c64cebe9ee331ec6b3c160e89Timo Sirainen for (unsigned int i = 0; i < 7; i++)
d78f1ac9dc0f3e6c64cebe9ee331ec6b3c160e89Timo Sirainen i_error("read(%s) failed: %s", i_stream_get_name(input),
68cc278710182485b6c09e9a9ff8db90a727f343Aki Tuomistruct doveadm_cmd_ver2 doveadm_cmd_reload_ver2 = {
c7713320cd35e77543f1bdc7229988a160dae322Timo Sirainenstruct doveadm_cmd_ver2 doveadm_cmd_service_stop_ver2 = {
c7713320cd35e77543f1bdc7229988a160dae322Timo SirainenDOVEADM_CMD_PARAM('\0', "service", CMD_PARAM_ARRAY, CMD_PARAM_FLAG_POSITIONAL)
eba7f36feec8d02c4c394e55ff4effd47e33d311Timo Sirainenstruct doveadm_cmd_ver2 doveadm_cmd_service_status_ver2 = {
eba7f36feec8d02c4c394e55ff4effd47e33d311Timo SirainenDOVEADM_CMD_PARAM('\0', "service", CMD_PARAM_ARRAY, CMD_PARAM_FLAG_POSITIONAL)
d78f1ac9dc0f3e6c64cebe9ee331ec6b3c160e89Timo Sirainenstruct doveadm_cmd_ver2 doveadm_cmd_process_status_ver2 = {