This is an alternative command to "del server". Its main difference is that
if the server cannot be immediately removed due to remaining active or idle
connections, the server is flagged for background deletion instead of
- rejecting the command. A scheduled deletion is cancelled if the server state
- is explicitly reset, even if still in maintenance mode.
+ rejecting the command. To succeed, this also automatically puts the server
+ into maintenance if needed. A scheduled deletion is cancelled if the server
+ state is explicitly reset, even if still in maintenance mode.
quit
Close the connection when in interactive mode.
return 1;
}
-/* Check if the server <bename>/<svname> exists and is ready for being deleted.
- * This means that the server is in maintenance with no streams attached to it,
- * no queue and no used idle conns. This is not supposed to change during all
- * the maintenance phase (except for force-persist etc, which are not covered).
- * Both <bename> and <svname> must be valid strings. If pb/ps are not null,
+/* Checks if the server <bename>/<svname> exists and is ready for being
+ * deleted. This means that the server is in maintenance with no streams
+ * attached to it, no queue and no used idle conns. This is not supposed to
+ * change during all the maintenance phase (except for force-persist etc, which
+ * are not covered). Both <bename> and <svname> must be valid strings.
+ *
+ * Input parameter <del_mode> indicates if the server deletion should be
+ * conducted immediately or could be performed in background. In the latter
+ * case, maintenance mode is set on the server if needed, instead of rejecting
+ * the deletion.
+ *
+ * If <pb>/<ps> are not null,
* upon success, the pointer to the backend and server respectively will be put
- * there. If pm is not null, a pointer to an error/success message is returned
- * there (possibly NULL if nothing to say). Returned values:
- * >0 if OK
- * 0 if not yet (should wait if it can)
- * <0 if not possible
+ * there. If <pm> is not null, a pointer to an error/success message is returned
+ * there (possibly NULL if nothing to say).
+ *
+ * Returns a positive value if server can be deleted. If not possible, 0 is
+ * returned if removal is temporarily blocked. A negative value is used if
+ * removal is blocked indefinitely due to its configuration or that it requires
+ * an administrative interaction.
*/
-int srv_check_for_deletion(const char *bename, const char *svname, struct proxy **pb, struct server **ps, const char **pm)
+int srv_check_for_deletion(const char *bename, const char *svname, enum pr_del_mode del_mode,
+ struct proxy **pb, struct server **ps, const char **pm)
{
struct server *srv = NULL;
struct proxy *be = NULL;
* lbprm.ops->set_server_status_down).
*/
if (!(srv->cur_admin & SRV_ADMF_MAINT)) {
- msg = "Only servers in maintenance mode can be deleted.";
- goto leave;
+ if (del_mode == PR_DEL_MODE_SYNC) {
+ msg = "Only servers in maintenance mode can be deleted.";
+ goto leave;
+ }
+
+ /* Automatically set server in maintenance for background deletion. */
+ srv_adm_set_maint(srv);
}
/* Second, conditions that may change over time */
goto out;
}
- ret = srv_check_for_deletion(be_name, sv_name, &be, &srv, &msg);
+ ret = srv_check_for_deletion(be_name, sv_name, PR_DEL_MODE_SYNC, &be, &srv, &msg);
if (ret <= 0) {
/* failure (recoverable or not) */
cli_err(appctx, msg);
goto out;
}
- ret = srv_check_for_deletion(be_name, sv_name, &be, &srv, &msg);
+ ret = srv_check_for_deletion(be_name, sv_name, PR_DEL_MODE_ASYNC, &be, &srv, &msg);
if (ret < 0) {
/* Unremovable server, cancel purge. */
cli_err(appctx, msg);