Timo002
Timo002

Reputation: 3208

Node.js on Plesk not starting

I have installed the Node.js Extension and I can't get my app running. I have a Symfony 4 application and I am using socket.io for socket communication. Now I need to startup socket.js to startup my server. This file is located in the resources/js folder.

So I have setup Node.js as below:

Document Root: /application.domain.com/public
Application Mode: production
Application URL: This site is under development
Application Root: /application.domain.com
Application Startup File: resources/js/socket.js
Custom environment variables:

But when I start the application, it is not working. When I run the socket.js file from CLI (SSH connection) like this

/opt/plesk/node/8/bin/node socket.js

It is working fine. But now I need to keep my SSH connection alive and there is no check if socket.js is still running. I suppose the Node.js extension also takes care for that.

How can I use this Node.js extension to startup up my socket.js? Or how could I do this in another way?

Upvotes: 0

Views: 1445

Answers (1)

Timo002
Timo002

Reputation: 3208

OK, I fixed this another way with Systemd.

Found this on https://www.axllent.org/docs/view/nodejs-service-with-systemd/, so credits to Ralph Slooten.

Create the service file

/etc/systemd/system/nodeserver.service

Content

[Unit]
Description=Node.js Example Server
#Requires=After=mysql.service       # Requires the mysql service to run first

[Service]
ExecStart=/usr/local/bin/node /opt/nodeserver/server.js
# Required on some systems
#WorkingDirectory=/opt/nodeserver
Restart=always
 # Restart service after 10 seconds if node service crashes
 RestartSec=10
 # Output to syslog
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=nodejs-example
#User=<alternate user>
#Group=<alternate group>
Environment=NODE_ENV=production PORT=1337

[Install]
WantedBy=multi-user.target

Enable the service

systemctl enable nodeserver.service

Start the service

systemctl start nodeserver.service

Upvotes: 1

Related Questions