I'm writing a node.js App.
In this directory (/var/lib/cloud9/BBB_WebApp$
) I have a package.json
:
{
"name": "MCP",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www",
"build": "browserify ./app.js > ./public/bundle.js"
},
"dependencies": {
"browserify": "^16.2.3",
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"express": "~4.16.0",
"graceful-fs": "^4.2.4",
"http-errors": "~1.6.2",
"i2c-bus": "^4.0.9",
"influx": "^5.4.0",
"jquery": "^3.3.1",
"morgan": "~1.9.0",
"node-crc": "^1.2.2",
"nodemailer": "^6.3.1",
"pug": "2.0.0-beta11",
"socket.io": "^2.1.1",
"socketcan": "^2.5.0",
"spi-device": "^2.0.9"
}
}
The app works fine with
/var/lib/cloud9/BBB_WebApp$ npm run start
or
/var/lib/cloud9/BBB_WebApp$ npm start
Now I want the app to start automatically after booting.
Therefore I use systemd
.
$ sudo nano /lib/systemd/system/Start_MCP.service
.
[Unit]
Description=Start MCP Service
After=network.target
[Service]
User=debian
ExecStart=/usr/bin/npm run start
WorkingDirectory=/var/lib/cloud9/BBB_WebApp/
#Restart=on-failure
StandardOutput=syslog
StandardError=syslog
[Install]
WantedBy=multi-user.target
.
$ systemctl daemon-reload
$ systemctl enable Start_MCP.service
$ systemctl start Start_MCP.service
After a few seconds. The service stops.
$ systemctl status Start_MCP.service
The syslog shows the following lines:
Oct 20 08:29:52 beaglebone systemd[1]: Started Start MCP Service.
Oct 20 08:29:59 beaglebone npm[9518]: > [email protected] start /var/lib/cloud9/BBB_WebApp
Oct 20 08:29:59 beaglebone npm[9518]: > node ./bin/www
Oct 20 08:30:03 beaglebone npm[9518]: module.js:478
Oct 20 08:30:03 beaglebone npm[9518]: throw err;
Oct 20 08:30:03 beaglebone npm[9518]: ^
Oct 20 08:30:03 beaglebone npm[9518]: Error: Cannot find module 'bonescript'
Oct 20 08:30:03 beaglebone npm[9518]: at Function.Module._resolveFilename (module.js:476:15)
Oct 20 08:30:03 beaglebone npm[9518]: at Function.Module._load (module.js:424:25)
Oct 20 08:30:03 beaglebone npm[9518]: at Module.require (module.js:504:17)
Oct 20 08:30:03 beaglebone npm[9518]: at require (internal/module.js:20:19)
Oct 20 08:30:03 beaglebone npm[9518]: at Object. (/var/lib/cloud9/BBB_WebApp/bin/www:26:9)
Oct 20 08:30:03 beaglebone npm[9518]: at Module._compile (module.js:577:32)
Oct 20 08:30:03 beaglebone npm[9518]: at Object.Module._extensions..js (module.js:586:10)
Oct 20 08:30:03 beaglebone npm[9518]: at Module.load (module.js:494:32)
Oct 20 08:30:03 beaglebone npm[9518]: at tryModuleLoad (module.js:453:12)
Oct 20 08:30:03 beaglebone npm[9518]: at Function.Module._load (module.js:445:3)
Oct 20 08:30:03 beaglebone npm[9518]: npm ERR! Linux 4.14.108-ti-r137
Oct 20 08:30:03 beaglebone npm[9518]: npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "start"
Oct 20 08:30:03 beaglebone npm[9518]: npm ERR! node v6.17.0
Oct 20 08:30:03 beaglebone npm[9518]: npm ERR! npm v3.10.10
Oct 20 08:30:03 beaglebone npm[9518]: npm ERR! code ELIFECYCLE
Oct 20 08:30:03 beaglebone npm[9518]: npm ERR! [email protected] start:node ./bin/www
Oct 20 08:30:03 beaglebone npm[9518]: npm ERR! Exit status 1
Oct 20 08:30:03 beaglebone npm[9518]: npm ERR!
Oct 20 08:30:03 beaglebone npm[9518]: npm ERR! Failed at the [email protected] start script 'node ./bin/www'.
Oct 20 08:30:03 beaglebone npm[9518]: npm ERR! Make sure you have the latest version of node.js and npm installed.
Oct 20 08:30:03 beaglebone npm[9518]: npm ERR! If you do, this is most likely a problem with the mcp package,
Oct 20 08:30:03 beaglebone npm[9518]: npm ERR! not with npm itself.
Oct 20 08:30:03 beaglebone npm[9518]: npm ERR! Tell the author that this fails on your system:
Oct 20 08:30:03 beaglebone npm[9518]: npm ERR! node ./bin/www
Oct 20 08:30:03 beaglebone npm[9518]: npm ERR! You can get information on how to open an issue for this project with:
Oct 20 08:30:03 beaglebone npm[9518]: npm ERR! npm bugs mcp
Oct 20 08:30:03 beaglebone npm[9518]: npm ERR! Or if that isn't available, you can get their info via:
Oct 20 08:30:03 beaglebone npm[9518]: npm ERR! npm owner ls mcp
Oct 20 08:30:03 beaglebone npm[9518]: npm ERR! There is likely additional logging output above.
Oct 20 08:30:03 beaglebone npm[9518]: npm ERR! Please include the following file with any support request:
Oct 20 08:30:03 beaglebone npm[9518]: npm ERR! /var/lib/cloud9/BBB_WebApp/npm-debug.log
Oct 20 08:30:03 beaglebone systemd[1]: Start_MCP.service: Main process exited, code=exited, status=1/FAILURE
Oct 20 08:30:03 beaglebone systemd[1]: Start_MCP.service: Unit entered failed state.
Oct 20 08:30:03 beaglebone systemd[1]: Start_MCP.service: Failed with result 'exit-code'.
What am I doing wrong ?
Why can I run the app with npm start normally but not with systemd service.
Why is bonescript not found.
Many thanks for your efforts.
The solution:
I can't explain why but reinstalling bonescript in the directory
...../BBB_WebApp$ npm install bonescript --save
has helped.