I managed to resolve this problem. I had installed the xrdp
server package a while ago for remote access to my Kubuntu server from a Windows system via Microsoft remote desktop, and it seems like it was competing with listening to the same port number 3389. It wasn’t clear at first since xrdp wasn’t shown as listening on this port (actually nothing was shown as listening on this port), but it came up once I reinstalled NoMachine. So I simply remove xrdp and restarted the NoMachine server, and the NX service now stays on/running.