-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(deployment): Add shutdown-on-startup and skip-upgrade properties…
… to support k8s init container use (#31003) (#31047) ### Proposed Changes * Add a FinalStartupServlet servlet that initializes after all other servlets that are set to run on startup. This will check for the shutdown-on-startup config property (DOT_SHUTDOWN_ON_STARTUP as an env var) default false, and if true the server will shut down with exit code 0 just before accepting connections. All startup initialization and upgrade tasks should have been completed. This can be used to run as an Init Container in K8s * Add a skip-upgrade config ( DOT_SKIP_UPGRADE ) default false. If set to true the DB startup tasks will not be attempted to be run. This can be used in a k8s pod replica when it is known that the upgrade tasks have been handled by the init container. There may not be much of a downside of leaving this off as it should detect the work has already been done, but this may help to reduce some unecessary work and also distinguish if there are some tasks that need to be run per instance vs per cluster/db. * Add and fix some logging helping to distinguish the location of startup steps between Servlets and ServletListeners. ### Testing At this stage a basic test that the server does shut down with exit 0 after all startup tasks when DOT_SHUTDOWN_ON_STARTUP=true is passed, and the fact that with the defaults, it does not impact any existing behavior is required. This will be further tested when implementing the init container that will make use of this flag.
- Loading branch information
Showing
7 changed files
with
68 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
dotCMS/src/main/java/com/dotmarketing/servlets/FinalStartupServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.dotmarketing.servlets; | ||
|
||
import com.dotmarketing.util.Config; | ||
import com.dotmarketing.util.Logger; | ||
import javax.servlet.ServletConfig; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServlet; | ||
//import javax.servlet.annotation.WebServlet; | ||
|
||
/** | ||
* This servlet is used to check if the server should be shutdown on startup. | ||
* If the property shutdown-on-startup is set to true, the server will be shutdown | ||
* The loadOnStartup is set to the highest value to ensure it is run after all other servlets that are not | ||
* lazy loaded | ||
*/ | ||
public class FinalStartupServlet extends HttpServlet { | ||
|
||
// init method | ||
@Override | ||
public void init(ServletConfig cfg) throws ServletException { | ||
super.init(cfg); | ||
Logger.info(this, "Starting FinalStartupServlet"); | ||
if (Config.getBooleanProperty("shutdown-on-startup", false)) { | ||
Logger.info(this, "shutdown-on-startup is true, shutting down the server"); | ||
System.exit(0); | ||
} | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
Logger.info(this, "FinalStartupServlet destroyed"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters