mirror of
https://github.com/corda/corda.git
synced 2025-06-17 06:38:21 +00:00
CORDA-1878: Improve exception handling when base directory is not readable or writable by the application user.
This commit is contained in:
@ -37,6 +37,7 @@ import org.slf4j.bridge.SLF4JBridgeHandler
|
|||||||
import sun.misc.VMSupport
|
import sun.misc.VMSupport
|
||||||
import java.io.Console
|
import java.io.Console
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.io.IOException
|
||||||
import java.io.RandomAccessFile
|
import java.io.RandomAccessFile
|
||||||
import java.lang.management.ManagementFactory
|
import java.lang.management.ManagementFactory
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
@ -426,9 +427,11 @@ open class NodeStartup(val args: Array<String>) {
|
|||||||
// exists, we try to take the file lock first before replacing it and if that fails it means we're being started
|
// exists, we try to take the file lock first before replacing it and if that fails it means we're being started
|
||||||
// twice with the same directory: that's a user error and we should bail out.
|
// twice with the same directory: that's a user error and we should bail out.
|
||||||
val pidFile = (baseDirectory / "process-id").toFile()
|
val pidFile = (baseDirectory / "process-id").toFile()
|
||||||
|
try {
|
||||||
pidFile.createNewFile()
|
pidFile.createNewFile()
|
||||||
val pidFileRw = RandomAccessFile(pidFile, "rw")
|
val pidFileRw = RandomAccessFile(pidFile, "rw")
|
||||||
val pidFileLock = pidFileRw.channel.tryLock()
|
val pidFileLock = pidFileRw.channel.tryLock()
|
||||||
|
|
||||||
if (pidFileLock == null) {
|
if (pidFileLock == null) {
|
||||||
println("It appears there is already a node running with the specified data directory $baseDirectory")
|
println("It appears there is already a node running with the specified data directory $baseDirectory")
|
||||||
println("Shut that other node down and try again. It may have process ID ${pidFile.readText()}")
|
println("Shut that other node down and try again. It may have process ID ${pidFile.readText()}")
|
||||||
@ -443,6 +446,12 @@ open class NodeStartup(val args: Array<String>) {
|
|||||||
val ourProcessID: String = ManagementFactory.getRuntimeMXBean().name.split("@")[0]
|
val ourProcessID: String = ManagementFactory.getRuntimeMXBean().name.split("@")[0]
|
||||||
pidFileRw.setLength(0)
|
pidFileRw.setLength(0)
|
||||||
pidFileRw.write(ourProcessID.toByteArray())
|
pidFileRw.write(ourProcessID.toByteArray())
|
||||||
|
} catch (ex: IOException) {
|
||||||
|
val appUser = System.getProperty("user.name")
|
||||||
|
println("Application user '$appUser' does not have necessary permissions for Node base directory '$baseDirectory'.")
|
||||||
|
println("Corda Node process in now exiting. Please check directory permissions and try starting the Node again.")
|
||||||
|
System.exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun initLogging(cmdlineOptions: CmdLineOptions) {
|
protected open fun initLogging(cmdlineOptions: CmdLineOptions) {
|
||||||
|
Reference in New Issue
Block a user