-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #10271 - new start.jar --pid-file=<name> arg
+ Have jetty.sh use --pid-file=<name> too Signed-off-by: Joakim Erdfelt <[email protected]>
- Loading branch information
Showing
4 changed files
with
104 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0"?> | ||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_9_3.dtd"> | ||
|
||
<!-- =============================================================== --> | ||
<!-- Mixin the Start FileNoticeLifeCycleListener --> | ||
<!-- =============================================================== --> | ||
<Configure id="Server" class="org.eclipse.jetty.server.Server"> | ||
<Call name="addEventListener"> | ||
<Arg> | ||
<New class="org.eclipse.jetty.util.component.PidFileLifeCycleListener"> | ||
<Arg><Property name="jetty.pid.file" default="./jetty.pid"/></Arg> | ||
</New> | ||
</Arg> | ||
</Call> | ||
</Configure> |
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
73 changes: 73 additions & 0 deletions
73
jetty-util/src/main/java/org/eclipse/jetty/util/component/PidFileLifeCycleListener.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,73 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995-2023 Mort Bay Consulting Pty Ltd and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.util.component; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class PidFileLifeCycleListener implements LifeCycle.Listener | ||
{ | ||
private static final Logger LOG = LoggerFactory.getLogger(PidFileLifeCycleListener.class); | ||
|
||
private final Path pidFile; | ||
|
||
public PidFileLifeCycleListener(String filename) | ||
{ | ||
pidFile = Paths.get(filename); | ||
} | ||
|
||
@Override | ||
public void lifeCycleStarting(LifeCycle event) | ||
{ | ||
long pid = ProcessHandle.current().pid(); | ||
try | ||
{ | ||
Files.writeString(pidFile, Long.toString(pid), StandardCharsets.UTF_8); | ||
} | ||
catch (IOException e) | ||
{ | ||
LOG.warn("Unable to create pidFile: {}", pidFile, e); | ||
} | ||
} | ||
|
||
@Override | ||
public void lifeCycleFailure(LifeCycle event, Throwable cause) | ||
{ | ||
removePid(); | ||
} | ||
|
||
@Override | ||
public void lifeCycleStopped(LifeCycle event) | ||
{ | ||
removePid(); | ||
} | ||
|
||
private void removePid() | ||
{ | ||
try | ||
{ | ||
Files.deleteIfExists(pidFile); | ||
} | ||
catch (IOException e) | ||
{ | ||
LOG.warn("Unable to remove pidFile: {}", pidFile, e); | ||
} | ||
} | ||
} |