ENT-6676 Don't log SSH port if shell not installed (#7059)

This commit is contained in:
Dan Newton 2022-02-11 14:05:05 +00:00 committed by GitHub
parent 0b8c46e1b2
commit 7afb585ae2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 8 deletions

View File

@ -687,10 +687,14 @@ abstract class AbstractNode<S>(val configuration: NodeConfiguration,
open fun startShell() {
if (configuration.shouldInitCrashShell()) {
val isShellStarted = InteractiveShell.startShellIfInstalled(configuration, cordappLoader)
configuration.sshd?.port?.let {
log.info("Binding Shell SSHD server on port $it.")
if (isShellStarted) {
log.info("Binding Shell SSHD server on port $it.")
} else {
log.info("SSH port defined but corda-shell is not installed in node's drivers directory")
}
}
InteractiveShell.startShellIfInstalled(configuration, cordappLoader)
}
}

View File

@ -263,11 +263,19 @@ open class NodeStartup : NodeStartupLogging {
Node.printBasicNodeInfo("Node for \"$name\" started up and registered in $elapsed sec")
// Don't start the shell if there's no console attached.
if (node.configuration.shouldStartLocalShell()) {
val isShellStarted = if (node.configuration.shouldStartLocalShell()) {
InteractiveShell.runLocalShellIfInstalled(node::stop)
} else {
false
}
if (node.configuration.shouldStartSSHDaemon()) {
Node.printBasicNodeInfo("SSH server listening on port", node.configuration.sshd!!.port.toString())
if (isShellStarted) {
Node.printBasicNodeInfo("SSH server listening on port", node.configuration.sshd!!.port.toString())
} else {
Node.printBasicNodeInfo(
"SSH server not started. SSH port is defined but the corda-shell is not installed in node's drivers directory"
)
}
}
},
{ th ->

View File

@ -17,28 +17,36 @@ object InteractiveShell {
private const val RUN_LOCAL_SHELL_METHOD = "runLocalShell"
private const val SET_USER_INFO_METHOD = "setUserInfo"
fun startShellIfInstalled(configuration: NodeConfiguration, cordappLoader: CordappLoader) {
if (isShellInstalled()) {
fun startShellIfInstalled(configuration: NodeConfiguration, cordappLoader: CordappLoader): Boolean {
return if (isShellInstalled()) {
try {
val shellConfiguration = configuration.toShellConfigMap()
setUnsafeUsers(configuration)
startShell(shellConfiguration, cordappLoader)
true
} catch (e: Exception) {
log.error("Shell failed to start", e)
false
}
} else {
false
}
}
/**
* Only call this after [startShellIfInstalled] has been called or the required classes will not be loaded into the current classloader.
*/
fun runLocalShellIfInstalled(onExit: () -> Unit = {}) {
if (isShellInstalled()) {
fun runLocalShellIfInstalled(onExit: () -> Unit = {}): Boolean {
return if (isShellInstalled()) {
try {
runLocalShell(onExit)
true
} catch (e: Exception) {
log.error("Shell failed to start", e)
false
}
} else {
false
}
}