suderman / smsglue

VoIP.ms SMS to Acrobits Softphone/Groundwire

Home Page:https://smsglue.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[question] How to startup script or service app

dragozet opened this issue · comments

Nice project! I have it running in CentOS 7 with your quick start instructions;

$ node
> require('smsglue').listen(5000)'

Question, as I'm a complete novice on node.js. How do I run the app in one line? I'd like to script it to auto-start on my server. Right now, using the quick start method, it doesn't return a prompt. How do I daemonize it or run as a service? Googling npm and node commands is making my head spin.

Thanks

I'm running smsglue.com on Ubuntu as a service using Systemd.

I created a file located at /lib/systemd/system/smsglue.com.service with the following contents:

[Unit]
Description=Node.js SMSglue.com Server
After=syslog.target network-online.target

[Service]
Type=simple
User=suderman
WorkingDirectory=/home/suderman/smsglue.com
Environment=NODE_ENV=production PORT=5000
ExecStart=/usr/bin/node /home/suderman/smsglue.com/index.js
Restart=on-failure
RestartSec=10
KillMode=process

[Install]
WantedBy=multi-user.target

And then I enable the service with sudo systemctl enable smsglue.com.service.

The directory structure of the smsglue.com app looks like this:

/home/suderman/smsglue.com/
  cache/
  node_modules/
  package-lock.json
  package.json
  index.js

The package.json referenced above is installed by running npm install and contains the following contents:

{
  "name": "smsglue.com",
  "version": "1.0.0",
  "description": "VoIP.ms SMS to Acrobits Softphone/Groundwire",
  "author": "suderman",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node ./index.js"
  },
  "dependencies": {
    "smsglue": "^1.0.0"
  }
}

The index.js file referenced above contains the following:

require('smsglue').listen(process.env.PORT || 5000);

I suppose the "one line" to pull from all this is /usr/bin/node /home/suderman/smsglue.com/index.js and that's what Systemd runs on boot.

I have no experience at all with CentOS, so I'm not sure how much of this work on that platform.

Good luck!

That's exactly what I was looking for and missing. That one line of code:

require('smsglue').listen(process.env.PORT || 5000);

in a file, and node is able to run it! I was trying to node run all the files with no avail. lol Learned a bit of node.js today.

I have it up and running now. Thank you!