Add stopping and starting of listeners to maxadmin

Listeners can now be stopped and started individually.
This commit is contained in:
Markus Makela
2016-11-28 16:04:51 +02:00
parent ecdeb009b3
commit 4ff4e69592
3 changed files with 85 additions and 7 deletions

View File

@ -225,6 +225,15 @@ bool serviceLaunchListener(SERVICE *service, SERV_LISTENER *port);
*/ */
bool serviceStopListener(SERVICE *service, const char *name); bool serviceStopListener(SERVICE *service, const char *name);
/**
* @brief Restart a stopped listener
*
* @param service Service where the listener is linked
* @param name Name of the listener
* @return True if listener was restarted
*/
bool serviceStartListener(SERVICE *service, const char *name);
/** /**
* Utility functions * Utility functions
*/ */

View File

@ -520,6 +520,31 @@ bool serviceStopListener(SERVICE *service, const char *name)
return rval; return rval;
} }
bool serviceStartListener(SERVICE *service, const char *name)
{
bool rval = false;
spinlock_acquire(&service->spin);
for (SERV_LISTENER *port = service->ports; port; port = port->next)
{
if (strcmp(port->name, name) == 0)
{
if (port->listener && port->listener->session->state == SESSION_STATE_LISTENER_STOPPED &&
poll_add_dcb(port->listener) == 0)
{
port->listener->session->state = SESSION_STATE_LISTENER;
rval = true;
}
break;
}
}
spinlock_release(&service->spin);
return rval;
}
int service_launch_all() int service_launch_all()
{ {
SERVICE *ptr; SERVICE *ptr;
@ -1422,18 +1447,20 @@ dListListeners(DCB *dcb)
if (service) if (service)
{ {
dcb_printf(dcb, "Listeners.\n"); dcb_printf(dcb, "Listeners.\n");
dcb_printf(dcb, "---------------------+--------------------+-----------------+-------+--------\n"); dcb_printf(dcb, "---------------------+---------------------+"
dcb_printf(dcb, "%-20s | %-18s | %-15s | Port | State\n", "--------------------+-----------------+-------+--------\n");
"Service Name", "Protocol Module", "Address"); dcb_printf(dcb, "%-20s | %-19s | %-18s | %-15s | Port | State\n",
dcb_printf(dcb, "---------------------+--------------------+-----------------+-------+--------\n"); "Name", "Service Name", "Protocol Module", "Address");
dcb_printf(dcb, "---------------------+---------------------+"
"--------------------+-----------------+-------+--------\n");
} }
while (service) while (service)
{ {
lptr = service->ports; lptr = service->ports;
while (lptr) while (lptr)
{ {
dcb_printf(dcb, "%-20s | %-18s | %-15s | %5d | %s\n", dcb_printf(dcb, "%-20s | %-19s | %-18s | %-15s | %5d | %s\n",
service->name, lptr->protocol, lptr->name, service->name, lptr->protocol,
(lptr && lptr->address) ? lptr->address : "*", (lptr && lptr->address) ? lptr->address : "*",
lptr->port, lptr->port,
(!lptr->listener || (!lptr->listener ||
@ -1447,7 +1474,8 @@ dListListeners(DCB *dcb)
} }
if (allServices) if (allServices)
{ {
dcb_printf(dcb, "---------------------+--------------------+-----------------+-------+--------\n\n"); dcb_printf(dcb, "---------------------+---------------------+"
"--------------------+-----------------+-------+--------\n\n");
} }
spinlock_release(&service_spin); spinlock_release(&service_spin);
} }

View File

@ -423,6 +423,19 @@ static void shutdown_server()
static void shutdown_service(DCB *dcb, SERVICE *service); static void shutdown_service(DCB *dcb, SERVICE *service);
static void shutdown_monitor(DCB *dcb, MONITOR *monitor); static void shutdown_monitor(DCB *dcb, MONITOR *monitor);
static void
shutdown_listener(DCB *dcb, SERVICE *service, const char *name)
{
if (serviceStopListener(service, name))
{
dcb_printf(dcb, "Stopped listener '%s'\n", name);
}
else
{
dcb_printf(dcb, "Failed to stop listener '%s'\n", name);
}
}
/** /**
* The subcommands of the shutdown command * The subcommands of the shutdown command
*/ */
@ -452,6 +465,14 @@ struct subcommand shutdownoptions[] =
"E.g. shutdown service \"Sales Database\"", "E.g. shutdown service \"Sales Database\"",
{ARG_TYPE_SERVICE, 0, 0} {ARG_TYPE_SERVICE, 0, 0}
}, },
{
"listener",
2, 2,
shutdown_listener,
"Stop a listener",
"E.g. shutdown listener \"RW Service\" \"RW Listener\"",
{ARG_TYPE_SERVICE, ARG_TYPE_STRING}
},
{ {
EMPTY_OPTION EMPTY_OPTION
} }
@ -487,6 +508,20 @@ struct subcommand syncoptions[] =
static void restart_service(DCB *dcb, SERVICE *service); static void restart_service(DCB *dcb, SERVICE *service);
static void restart_monitor(DCB *dcb, MONITOR *monitor); static void restart_monitor(DCB *dcb, MONITOR *monitor);
static void
restart_listener(DCB *dcb, SERVICE *service, const char *name)
{
if (serviceStartListener(service, name))
{
dcb_printf(dcb, "Restarted listener '%s'\n", name);
}
else
{
dcb_printf(dcb, "Failed to restart listener '%s'\n", name);
}
}
/** /**
* The subcommands of the restart command * The subcommands of the restart command
*/ */
@ -504,6 +539,12 @@ struct subcommand restartoptions[] =
"E.g. restart service \"Sales Database\"", "E.g. restart service \"Sales Database\"",
{ARG_TYPE_SERVICE, 0, 0} {ARG_TYPE_SERVICE, 0, 0}
}, },
{
"listener", 2, 2, restart_listener,
"Restart a listener",
"E.g. restart listener \"RW Service\" \"RW Listener\"",
{ARG_TYPE_SERVICE, ARG_TYPE_STRING}
},
{ EMPTY_OPTION } { EMPTY_OPTION }
}; };