Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use forever within a Docker container

I want to run my simple Node server as a background process within my Docker container but when I try and fire it up using forever I get the following:

fs.js:432
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
Error: ENOENT, no such file or directory '/.forever/9Spa.log'

So I tried just making a folder called .forever in my current working directory but then I got pretty much the same error (the *.log file has a different name each time I run it, as expected.)

If I run my server without using forever it runs fine without any errors. E.g:

node server

or

npm start

both work fine, but of course don't run in the background.

I get the same error just running

forever list

So the issue it clearly with forever and not my server code.

npm list -g shows that forever is installed.

I am using a Ubuntu 14.04.1 LTS image in my Docker container.

I'm open to suggestions.

update

I finally got forever to run my making a .forever folder in /home/testuser and within that a pids folder, then running the following:

forever start -p /home/testuser/.forever --pidFile /home/testuser/.forever/pids/server.pid server.js

According to the docs

-p PATH Base path for all forever related files (pid files, etc.)

However that's not quite true. I was forced to specify the absolute path for the --pidFile

So, hooray, my server is running as a background process. However the following still break:

forever stop server.js

=> /usr/local/lib/node_modules/forever/lib/forever.js:634 var procs = processes.filter(function (p) { ^ TypeError: Object Error: EACCES, mkdir '/.forever' has no method 'filter' at Object.forever.findByScript (/usr/local/lib/node_modules/forever/lib/forever.js:634:25) at /usr/local/lib/node_modules/forever/lib/forever.js:189:20 at /usr/local/lib/node_modules/forever/lib/forever.js:136:14 at /usr/local/lib/node_modules/forever/lib/forever.js:89:20 at /usr/local/lib/node_modules/forever/node_modules/utile/node_modules/mkdirp/index.js:34:29 at /usr/local/lib/node_modules/forever/node_modules/utile/node_modules/mkdirp/index.js:46:53 at Object.oncomplete (fs.js:107:15)

forever stop -p /home/bit2bit/.forever server.js

same result

forever list

==> /usr/local/lib/node_modules/forever/lib/forever.js:683 procs.forEach(function (proc) { ^ TypeError: Object Error: EACCES, mkdir '/.forever' has no method 'forEach' at Object.forever.format (/usr/local/lib/node_modules/forever/lib/forever.js:683:11) at /usr/local/lib/node_modules/forever/lib/forever.js:520:28 at /usr/local/lib/node_modules/forever/lib/forever.js:136:14 at /usr/local/lib/node_modules/forever/lib/forever.js:89:20 at /usr/local/lib/node_modules/forever/node_modules/utile/node_modules/mkdirp/index.js:34:29 at /usr/local/lib/node_modules/forever/node_modules/utile/node_modules/mkdirp/index.js:46:53 at Object.oncomplete (fs.js:107:15)

So, while I can now start my server, I can't stop it again.

like image 981
Dave Sag Avatar asked Oct 31 '22 18:10

Dave Sag


1 Answers

Where does forever store console.log output?

try adding a -o argument to specify where the log will be output to.

like image 70
Sam Hodge Avatar answered Nov 09 '22 11:11

Sam Hodge