cardano-community / guild-operators

Artifacts and scripts created by Guild operators
https://cardano-community.github.io/guild-operators
MIT License
354 stars 177 forks source link

Wrong version detected in case of multiple cardano-node executables #1071

Closed safanaj closed 3 years ago

safanaj commented 3 years ago

Describe the bug the gLiveView.sh script is detecting a wrong version of cardano-node in case of the running node process is executed using a binary named differently than cardano-node. In case of multiple version installation, like cardano-node-X.Y.Z and cardano-node the gLiveView.sh script is not able to detect the correct version assuming that there is an executable named cardano-node.

To Reproduce

  1. Install cardano-node version 1.27.0 binary in PATH , naming it cardano-node
  2. Install cardano-node version 1.29.0 binary in PATH , naming it cardano-node-1.29.0
  3. Execute the cardano-node-1.29.0

Additional context I found useful to maintain installed several version of cardano-node and cardano-cli installed on my nodes, an during some testing upgrades or other migrations I don't want to have to stick to a binary named cardano-node

The issue is caused by this lines:

Would be good if using the CNODE_PID variable (detected) the scripts would find the exact executable for the running process using something like:

cat /proc/${CNODE_PID}/cmdline |tr '\0' ' ' | cut -f1 -d' ' 
rdlrt commented 3 years ago

Would be good if using the CNODE_PID variable (detected) the scripts would find the exact executable for the running process using something like

The CNODE_PID is found using grep for [c]ardano-node.*.port.. So your suggestion would not work.

I think we could add a change for being able to specify exact path & binary name in env file (similar to CCLI , but for node)

orpheus-antpool commented 3 years ago

On the other hand, only one process can listed to the EKG or Prometheus port and we can get it's PID, for example: PID=$(fuser -n tcp $PROM_PORT | cut -f 2)

rdlrt commented 3 years ago

Hmm, but EKG_PORT/PROM_PORT are derived from CONFIG, which is captured from command line used to run the node (if a custom CONFIG isnt specified). Because users can accidentally rush into running node without modifying configs/paths/env correctly (based on countless support requests), the flow was adopted to:

  1. Check command line of node
  2. Extract config file specified for node
  3. Parse config file for settings (including EKG/PROM host/port among other things like genesis). The other important part to have this in place was also ensuring those who do not use guild folder structure to not be impacted by assumptions.

I suppose if we had to use port to check process, we could go for node listen port itself (for which we'd have to use ss -tlnp "sport = :${CNODE_PORT}" | grep LISTEN | sed -e 's/.*.pid=\(.*\),.*/\1/g' and fallback to lsof -i -P -n | grep ${CNODE_PORT}.*.LISTEN |awk '{print $2}' instead of fuser, since fuser may not be present on all flavour of Linux - while ss/lsof is used by gLiveView as well.

But then we'd need cardano-node process name for cnode.sh itself - that's used to start the node. Hence, if we'd have to cater for node binary name regardless, I think existing solution works best if adapted to allow specifying node binary name via env file?

orpheus-antpool commented 3 years ago

Well, if you have the PID, you can easily get the name of the process: "ps -p $PID -o comm". But yes, if you need to start the process to begin with, then the name of the executable needs to be specified in env.