Home > Software design >  pm2 process using the old system Environment Variables on resurrection
pm2 process using the old system Environment Variables on resurrection

Time:04-01

I have created a node application that is for subscribing to an OPC-UA server and storing the data on our s3 bucket. I am using the node-opcua module for that purpose.

I am working on a Windows server via RDP and the node-opcua module creates some files under %LOCALAPPDATA%\Temp as part of the process and uses it. I am using pm2 to run the application and it is getting the path of those files via TMP and TEMP environment variables which are dynamically generated by the process itself.

When the Windows server restarts it delete those files and the location updates of the new file. I already have run pm2 save and put the pm2 resurrect command in the Batch file which has a shortcut in the windows startup to make sure the process automatically gets started.

The issue was that the pm2 process was resurrected but still throwing the error %LOCALAPPDATA%\Temp\{some_path} file not found by the node-opcua process which was running through pm2. I ran pm2 restart manually but still didn't work out.

CodePudding user response:

First I was thinking of it from the problem with the node-opcua module and thought about how can make it use the new system variables, but that was not in had as the process keeps making and deleting temporary files, so I need the pm2 to use the new system variable which has the updated path after system reboot and was not updating even after pm2 restart.

So, for updating the variables I figured out two solutions:

  • Either delete the old process and initiate a new pm2 process to run that application and put it in the batch file which is being called at server reboot
  • Adds pm2 restart {name} --update-variable after pm2 resurrect and the system variables will be updated.
  • Related