Nodejs app doesn't start correctly with forever after reload

I have a nodejs app that I want to restart automatically after a server restart. I created a script to run the application forever like below.

#!/bin/sh
export PATH=/usr/bin:$PATH
forever start --command node --minUptime 1000 --spinSleepTime 10000 --sourceDir /etc/csc server.js >> /etc/csc/log.txt 2>&1

      

I also created a crontab entry to run this script after reboot:

@reboot /etc/csc/csc-starter.sh

      

Although, I don't think the crontab part is really relevant, as I'll explain below. The problem is that although the nodejs app starts after reloading, it is not responding to client requests. For example, calling a URL that should render the main view of the displayed application (in the browser) results in the following output:

{
code: "ResourceNotFound",
message: "/"
}

      

Interestingly, the same output is observed when I run the script starter manually. However, if I run my nodejs app with:

node /etc/csc/server.js

      

it works fine. I'm a relative newbie to Linux, and you can safely assume that I may not be aware of some of the accepted truths about working in Linux, such as the possibility of placing an application under / etc.

Any ideas why launching the app would permanently change its internal behavior? This application is pretty simple. It is restore based and has multiple REST routes as well as static content placement, but it really doesn't represent anything.

Thank.

+3


source to share


2 answers


/ etc is probably not the best place for your application. Although this is not directly related to your problem.

When you manually start the application from the command line, you are probably already in the / etc / csc directory.

Try adding the changes to the directory when you run the script:

#!/bin/sh
export PATH=/usr/bin:$PATH
cd /etc/csc
forever start --command node --minUptime 1000 --spinSleepTime 10000 --sourceDir /etc/csc server.js >> /etc/csc/log.txt 2>&1

      



The application may be configured to use a subdirectory from the current directory for its static resources.

-

You should consider placing your application in / opt / csc. This is a more general place for third party apps. / etc is more for system configuration.

+3


source


/etc/csc server.js >>

      

Remove the space in the path.



/etc/csc/server.js >>

      

0


source







All Articles