@blanchsb that is indeed tricky! When I was in a situation like this (actually also with hydraulic cylinders), I made a small ‘rig’;
using Empties at the ends of the cylinder, parenting (or using Copy Location and Copy Rotation Constraints,,,) the two parts of the cylinder to the Empties and a Damped Track Constraint so that I could just snap the two Empties to their positions and the cylinder would follow…Somethiong like that, can’t remember exactly;)