zapty / forever-service

Provision node script as a service via forever, allowing it to automatically start on boot, working across various Linux distros and OS
https://github.com/zapty/forever-service
MIT License
594 stars 65 forks source link

runAsUser appears to be ignored on reboot on fedora 22 #46

Closed kellyselden closed 8 years ago

kellyselden commented 8 years ago

I know runAsUser is experimental, so apologies if this is a known issue. I've successfully used runAsUser with the following setup:

sudo touch /var/run/testApp.pid
sudo chown testUser /var/run/testApp.pid
sudo forever-service install testApp --script /usr/bin/testApp/app.js --foreverOptions " --append --pidFile /var/run/testApp.pid --uid testApp --workingDir /usr/bin/testApp --watch --watchDirectory /usr/bin/testApp" --start --runAsUser testUser

The logs show it is working. But on reboot, the logs say:

fs.js:584
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^

Error: EACCES: permission denied, open '/var/run/testApp.pid'
    at Error (native)
    at Object.fs.openSync (fs.js:584:18)
    at Object.fs.writeFileSync (fs.js:1224:33)
    at writePid (/usr/local/.nvm/versions/node/v5.1.1/lib/node_modules/forever/b
in/monitor:13:6)
    at null.<anonymous> (/usr/local/.nvm/versions/node/v5.1.1/lib/node_modules/f
orever/bin/monitor:46:5)
    at EventEmitter.emit (/usr/local/.nvm/versions/node/v5.1.1/lib/node_modules/
forever/node_modules/eventemitter2/lib/eventemitter2.js:339:22)
    at /usr/local/.nvm/versions/node/v5.1.1/lib/node_modules/forever/node_module
s/forever-monitor/lib/forever-monitor/monitor.js:175:10
    at doNTCallback0 (node.js:430:9)
    at process._tickCallback (node.js:359:13)

It appears on reboot it switches to running as root.

arvind-agarwal commented 8 years ago

@kellyselden /var/run folder is mounted on tmpfs and is reset on each reboot, so the user configuration on that will disappear. Hence you are getting an error on reboot, and this will happen in all Linux variants.

Also it is probably not good to rely on pid file from forever since pid might change if process is recycled for any reason. Thats why internally forever-service does not depend upon pid obtained during initial run of forever.

If you remove pidFile parameter it should work on reboot as well.

kellyselden commented 8 years ago

Thanks, this is beginning to make more sense. I'm learning which options I can and can't transfer over from a plain forever setup.