When runing a Node.JS app from WHM/cPanel Application Manager, the Passenger file is missing "PassengerStartupFile" and won't actually run - node.js

I've installed Node.JS via cPanel and all the Phusion Passenger files and dependencies. I can run the application manually via SSH. I have created the application in cPanel's Application Manager. However, after the application is "enabled" it's not actually "running" and only results in the Passenger error page. It says it was not able to execute the application.
If I manually inspect the application configuration file in /etc/apache2/conf.d/userdata/ssl/2_4/username/subdomain/application_name.conf I can see it doesn't have an entry for PassengerStartupFile. If I add the line
PassengerStartupFile ./bin/www
and restart the Passenger service, is works and I can access it via the URL. However, if I disable and re-enable the application via cPanel, the conf file is regenerated and that entry is lost.
How can I get cPanel to add the PassengerStartupFile entry, or get Passenger to auto-detect the startup file from the package.json file or environment variables or something?
As a work-around, I've created a second application_name_patch.conf file with the missing configuration line so that it all eventually gets compiled together, but that's kludgy...

Your solution to add a second application_name_patch.conf file next to the appliation_name.conf file is exactly the solution you need as is explained here: How to Install a Node.js Application.
The linked article suggests you use the path /etc/apache2/conf.d/userdata/ssl/2_4/user/domain.nodejs.conf for the custom startup file, but I would recommend you use the path /etc/apache2/conf.d/userdata/ssl/2_4/user/domain/nodejs.conf as this will place the custom configuration in the same directory as the original application conf file.

Related

Phusion Passenger: 'Initialize language runtime' and 'Load or execute application' error with nodejs app

My nodejs app works fine on my local machine in the dev environment, however getting it to work on the production server is a nightmare.
In a nutshell the app is starting but the content is not loading on the site. It is failing to fully initialize as the screenshot shows.
Screenshot
Anyone have any ideas about this? Even the hosting company isn't sure what is causing it and I can't find anything relevant on google so far. All I know is it is coming from Phusion Passenger...
I will post my solution in case anyone else runs into this issue.
If you have created a nodejs app using express and have used the express generator to set the app up, you will notice the start up file is called www inside the bin folder in your projects directory. Usually it is named app.js.
Phusion Passenger looks for app.js to start the app. You need to tell Phusion Passenger to look for ./bin/www inside your config file. It will likely be different for different systems. In apache it is located here:
/etc/apache2/conf.d/userdata/std/2_4/YOUR_USERNAME/YOUR_DOMAIN/YOUR_APPNAME.conf
You need to add this startup file line:
PassengerStartupFile ./bin/www
Your config file should look something like this:
<Location "/">
<IfModule mod_passenger.c>
PassengerAppEnv "development"
PassengerEnabled on
PassengerBaseURI "/"
PassengerAppRoot "/home/YOUR_USERNAME/YOUR_DOMAIN"
PassengerAppGroupName "YOUR_APP_NAME"
PassengerRuby /opt/cpanel/ea-ruby27/root/usr/libexec/passenger-ruby27
PassengerPython /usr/bin/python
PassengerNodejs /opt/cpanel/ea-nodejs10/bin/node
PassengerAppType node
PassengerStartupFile ./bin/www
</IfModule>
</Location>
Then you just need to save the file, rebuild the apache http config file and restart apache.
I used the terminal inside WHM to run these two lines:
1# /usr/local/cpanel/scripts/rebuildhttpdconf
2# /usr/local/cpanel/scripts/restartsrv_httpd
The instructions in this post are found here:
https://docs.cpanel.net/knowledge-base/web-services/how-to-install-a-node.js-application/

Folder structure to deploy app on EC2 instance

I am setting up a new React app on EC2 instance (ubuntu). I have installed nodeJS and npm and I am able to build my app successfully.
Issue is my code is in /var/www/html folder and my site example.com is pointed to this folder.
when I run
npm run build
It builds a folder under /html like /html/build now my app runs on example.com/build. Resources for these files comes from example.com/static/style.css etc but they actually reside under example.com/build/static
I can edit asset-manifest.json and change the path but thats not appropriate solution as I need to get rid of /build folder for production
I am not super familiar with deployments to EC2 but this looks like you just need to either copy the entire contents of your app inside var/www/html, or you need to tell apache or nginx to look to the right folder (in this case /build)
For example, with apache you probably have a file inside /etc/apache2/sites-enabled/ that is pointing to /var/www/html, you could change that to /var/www/html/build and restart apache.
You can check this for examples on how to write these configurations https://gist.github.com/rambabusaravanan/578df6d2486a32c3e7dc50a4201adca4

How to deploy shield with Kibana on Bluemix

I am trying to deploy Kibana on Bluemix PaaS. Because Kibana is a Node.js application, it can be deployed as such on Bluemix. All i have to do:
Provide a simple manifest.yml file that details the app name and a couple of other things
Provide a Procfile that has just one line as web: bin/kibana --port=$PORT
Thus, I can run Kibana on Bluemix. Note that this is pushed via Cloud Foundry.
Also, I was able to install the marvel and sense plugins for Kibana.
Now, I installed the shield plugin. This plugin requires an ssl key and an ssl cert file to run. The path to these files must be provided in the kibana.yml file.
After installation, I tested the shield plugin natively and it worked just fine.
Here is the layout of the directory structure:
bin(d)
config(d)
installedPlugins(d)
node_modules(d)
sslFiles(d)
manifest.yml
Procfile
(d) represents directories. The sslFiles folder contains the ssl key and ssl cert files.
Before I could push to Bluemix, I knew that the paths to the SSL files would have to be relative to the app in Bluemix. Thus, in the kibana.yml file, I specified them as:
kibana.ssl.key:app/sslFiles/kibana.key
kibana.ssl.cert:app/sslFiles/kibana.cert
I did this as in Bluemix, I could see the following directory structure:
app(d)
bin(d)
config(d)
installedPlugins(d)
node_modules(d)
sslFiles(d)
manifest.yml
Procfile
Indentation represents containment. So, I pushed it to Bluemi using Cloud Foundry, but now I get a 502 Bad Gateway: Registered endpoint failed to handle the request error. I tried changing the paths to sslFiles/kibana.key but then I got a cannot find path sslFiles/kibana.key staging error.
What is responsible for my 502 error? Is it the path to the sslFiles? If so, how can I properly provide the paths?

Tomcat Intellij Idea: Remote deploy

RackSpace Cloud Server Ubuntu-12.04, Intellij Idea-11.1.2, Windows-8, Tomcat-7.0.26, JDK-6.
On Intellij Idea when i try to run jsf project on my remote Tomcat 7 server it says:
Error running servername: Unable to connect to the ip-address:1099
It seems problem is about JNDI port which is 1099 but I couldn't activate it I guess. Tomcat config is sth. like that:
What I've tried?
Setting CATALINA_OPTS or JAVA_OPTS on the server side with:
CATALINA_OPTS=-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=1099
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
and
JAVA_OPTS=-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=1099
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
But this one did not work, any ideas?
My answer to my question:
The correct way to deploy remotely is editing JAVA_OPTS environment variable on the remote server. Just enter the command below:
export JAVA_OPTS="-Dcom.sun.management.jmxremote=
-Dcom.sun.management.jmxremote.port=1099
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false"
If that's not going to work and if you don't have any obsession to deploy your website via Intellij Idea, I've got the solution for this problem. To be able to run your website under Tomcat, you can/should get artifact in form of .war file.
It can be done in Intellij from project settings(ctrl+alt+shift+s) then hit the plus button and add new artifact(web:application archieve)
After rebuilding the artifact, .war file can be seen in project-folder\out\artifacts. Next, you should place this file into your tomcat/webapps folder.
For example if you are using Tomcat-7, the folder that I mean exists in /var/lib/tomcat7/webapps. Before copying your .war file you should rename it as ROOT.war. This provides to access your site directly by http://youripaddress:8080. After restarting Tomcat7 service you can access the site.
But not finished yet, you can debug your project remotely like you are debugging your project at your local machine with Intellij Idea. Open Run/Debug Configuration in Idea, hit the plus button and there must be Remote. This is the way to debug your projects for application servers like JBoss, Glassfish as well in Idea. Enter your host and port numbers, select your project as a module.
Before starting to debug, as Intellij says you should give the following parameter to your server JVM:
JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"
To be able to do that in Ubuntu and for Tomcat-7, modified the catalina.sh file in usr/share/tomcat7 folder. I inserted the parameter above of the if [ -z "$LOGGING_MANAGER" ]; then line. It must be on the middle part of the file. Then you should be able to debug your project with Intellij Idea.

Where is the log file using Production profile with NServiceBus GenericHost and default log4net settings when installed as a service?

I have a very simple NServiceBus.Host.exe application that is using the default logging and the Production profile. According to the documentation, this should result in an appending file log that should appear in the same folder as the EXE. However, when I run the application as a service, the log file doesn't appear in the same folder as the EXE, and thus far I've been unable to locate it at all. The service is running as Local System. Do I need to run it as a user account and look for the file in the AppData folder somewhere? Is it under c:\windows somewhere? Where is it and is there a way for me to have it actually log to a file in the same folder as the EXE as advertised?
Update:
Using ProcMon and ProcExp from SysInternals, I can see that there is no attempt to create any log file in the folder where my EXE exists, nor are there any file permission errors while trying to create a log file anywhere, at least not from the PID of the service (if for some reason log4net spins up another process to do this work then I might have missed it).
It turns out that the service wasn't actually running in the Production profile. I had for some reason gotten it into my head that services would run in the production profile by default, while running it in interactive mode would use Lite by default. Not so - the service will use the Lite profile unless you specify otherwise. I changed my command to install the service from:
NServiceBus.Host.exe /install /displayName:MyService
to
NServiceBus.Host.exe /install /displayName:MyService NServiceBus.Production
and this fixed the issue.

Resources