Reputation: 353
I can't seem to be able to start my express server through Systemd (ExecStart=/usr/bin/npm run start). It does work when I run the command manually. Here is the stack trace:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node',
1 verbose cli '/usr/bin/npm',
1 verbose cli 'run',
1 verbose cli 'start',
1 verbose cli '--prefix',
1 verbose cli '/opt/par/p-web' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle [email protected]~prestart: [email protected]
6 info lifecycle [email protected]~start: [email protected]
7 verbose lifecycle [email protected]~start: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~start: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/opt/par/p-web/node_modules/.bin:/usr/bin:/usr/local/bin
9 verbose lifecycle [email protected]~start: CWD: /opt/par/p-web
10 silly lifecycle [email protected]~start: Args: [ '-c', 'node server/server.js' ]
11 info lifecycle [email protected]~start: Failed to exec start script
12 silly lifecycle [email protected]~start: Returned: code: -2 signal: null
13 info lifecycle [email protected]~start: Failed to exec start script
14 verbose stack Error: [email protected] start: `node server/server.js`
14 verbose stack spawn sh ENOENT
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:232:19)
14 verbose stack at onErrorNT (internal/child_process.js:407:16)
14 verbose stack at process._tickCallback (internal/process/next_tick.js:63:19)
15 verbose pkgid [email protected]
16 verbose cwd /opt/par/p-web
17 verbose Linux 4.4.0-1072-aws
18 verbose argv "/usr/bin/node" "/usr/bin/npm" "run" "start" "--prefix" "/opt/par/p-web"
19 verbose node v10.13.0
20 verbose npm v6.4.1
21 error file sh
22 error path sh
23 error code ELIFECYCLE
24 error errno ENOENT
25 error syscall spawn sh
26 error [email protected] start: `node server/server.js`
26 error spawn sh ENOENT
27 error Failed at the [email protected] start script.
27 error This is probably not a problem with npm. There is likely additional logging output above.
28 verbose exit [ 1, true ]
Any ideas?
Upvotes: 2
Views: 3130
Reputation: 874
I was seeing a spawn sh ENOENT
error when trying to run an executable using npx
through systemd. I noticed that when I ran the command under nohup
(from the service file), it complained about not being able to find bash
. Making sure both Node and bash
were on my path fixed the issue, even after I took the nohup
out of the service file.
In summary, try adding something like this to your service file's Service unit:
Environment="PATH=/path/to/your/node/bin:/usr/bin"
Upvotes: 2