mirror of
https://github.com/corda/corda.git
synced 2025-04-15 06:56:59 +00:00
Moved node directory creation into the abstract node.
This commit is contained in:
parent
58d5162782
commit
86b5b7299a
@ -121,6 +121,8 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration,
|
||||
require(!started) { "Node has already been started" }
|
||||
log.info("Node starting up ...")
|
||||
|
||||
createNodeDir()
|
||||
|
||||
val storageServices = initialiseStorageService(dir)
|
||||
storage = storageServices.first
|
||||
checkpointStorage = storageServices.second
|
||||
@ -316,4 +318,10 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration,
|
||||
}
|
||||
return NodeAttachmentService(attachmentsDir, services.monitoringService.metrics)
|
||||
}
|
||||
|
||||
private fun createNodeDir() {
|
||||
if (!Files.exists(dir)) {
|
||||
Files.createDirectories(dir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import org.glassfish.jersey.servlet.ServletContainer
|
||||
import java.io.RandomAccessFile
|
||||
import java.lang.management.ManagementFactory
|
||||
import java.nio.channels.FileLock
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.time.Clock
|
||||
import javax.management.ObjectName
|
||||
@ -164,22 +165,24 @@ class Node(dir: Path, val p2pAddr: HostAndPort, configuration: NodeConfiguration
|
||||
// file that we'll do our best to delete on exit. But if we don't, it'll be overwritten next time. If it already
|
||||
// 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.
|
||||
val pidPath = dir.resolve("process-id")
|
||||
val file = pidPath.toFile()
|
||||
if (!file.exists()) {
|
||||
file.createNewFile()
|
||||
if(Files.exists(dir)) {
|
||||
val pidPath = dir.resolve("process-id")
|
||||
val file = pidPath.toFile()
|
||||
if (!file.exists()) {
|
||||
file.createNewFile()
|
||||
}
|
||||
file.deleteOnExit()
|
||||
val f = RandomAccessFile(file, "rw")
|
||||
val l = f.channel.tryLock()
|
||||
if (l == null) {
|
||||
println("It appears there is already a node running with the specified data directory $dir")
|
||||
println("Shut that other node down and try again. It may have process ID ${file.readText()}")
|
||||
System.exit(1)
|
||||
}
|
||||
nodeFileLock = l
|
||||
val ourProcessID: String = ManagementFactory.getRuntimeMXBean().name.split("@")[0]
|
||||
f.setLength(0)
|
||||
f.write(ourProcessID.toByteArray())
|
||||
}
|
||||
file.deleteOnExit()
|
||||
val f = RandomAccessFile(file, "rw")
|
||||
val l = f.channel.tryLock()
|
||||
if (l == null) {
|
||||
println("It appears there is already a node running with the specified data directory $dir")
|
||||
println("Shut that other node down and try again. It may have process ID ${file.readText()}")
|
||||
System.exit(1)
|
||||
}
|
||||
nodeFileLock = l
|
||||
val ourProcessID: String = ManagementFactory.getRuntimeMXBean().name.split("@")[0]
|
||||
f.setLength(0)
|
||||
f.write(ourProcessID.toByteArray())
|
||||
}
|
||||
}
|
||||
|
@ -50,12 +50,7 @@ fun main(args: Array<String>) {
|
||||
// Suppress the Artemis MQ noise, and activate the demo logging.
|
||||
BriefLogFormatter.initVerbose("+demo.ratefix", "-org.apache.activemq")
|
||||
|
||||
// TODO: Move this into the AbstractNode class.
|
||||
val dir = Paths.get(options.valueOf(dirArg))
|
||||
if (!Files.exists(dir)) {
|
||||
Files.createDirectory(dir)
|
||||
}
|
||||
|
||||
val networkMapAddr = ArtemisMessagingService.makeRecipient(options.valueOf(networkMapAddrArg))
|
||||
val networkMapIdentity = Files.readAllBytes(Paths.get(options.valueOf(networkMapIdentityArg))).deserialize<Party>()
|
||||
val networkMapAddress = NodeInfo(networkMapAddr, networkMapIdentity)
|
||||
|
@ -95,7 +95,7 @@ fun main(args: Array<String>) {
|
||||
// for protocols will change in future.
|
||||
BriefLogFormatter.initVerbose("+demo.buyer", "+demo.seller", "-org.apache.activemq")
|
||||
|
||||
val directory = setupDirectory(role)
|
||||
val directory = Paths.get(DIRNAME, role.name.toLowerCase())
|
||||
|
||||
// Override the default config file (which you can find in the file "reference.conf") to give each node a name.
|
||||
val config = run {
|
||||
@ -141,12 +141,6 @@ fun main(args: Array<String>) {
|
||||
}
|
||||
}
|
||||
|
||||
fun setupDirectory(mode: Role): Path {
|
||||
val directory = Paths.get(DIRNAME, mode.name.toLowerCase())
|
||||
Files.createDirectories(directory)
|
||||
return directory
|
||||
}
|
||||
|
||||
fun parseOptions(args: Array<String>, parser: OptionParser): OptionSet {
|
||||
try {
|
||||
return parser.parse(*args)
|
||||
|
Loading…
x
Reference in New Issue
Block a user