What's going wrong?
How could we reproduce this issue?
Since some updates of pm2 i can't start pm2 as a user different than root. I had this issue some weeks ago also but it fixed itself.
root@server:~# env PATH=$PATH:/usr/local/bin pm2 startup ubuntu -u thelounge --hp /home/thelounge
[PM2] Init System found: systemd
-----------------------------------------------------------
PM2 detected systemd but you precised ubuntu
Please verify that your choice is indeed your init system
If you arent sure, just run : pm2 startup
-----------------------------------------------------------
Platform ubuntu
Template
[Unit]
Description=PM2 process manager
Documentation=https://pm2.keymetrics.io/
After=network.target
[Service]
Type=forking
User=thelounge
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Environment=PATH=/usr/local/bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Environment=PM2_HOME=/home/thelounge/.pm2
PIDFile=/home/thelounge/.pm2/pm2.pid
ExecStart=/usr/local/lib/node_modules/pm2/bin/pm2 resurrect
ExecReload=/usr/local/lib/node_modules/pm2/bin/pm2 reload all
ExecStop=/usr/local/lib/node_modules/pm2/bin/pm2 kill
[Install]
WantedBy=multi-user.target
Target path
/etc/systemd/system/pm2-thelounge.service
Command list
[ 'chmod +x /etc/systemd/system/pm2-thelounge.service',
'systemctl enable pm2-thelounge',
'systemctl start pm2-thelounge',
'systemctl daemon-reload',
'systemctl status pm2-thelounge' ]
[PM2] Writing init configuration in /etc/systemd/system/pm2-thelounge.service
[PM2] Making script booting at startup...
>>> Executing chmod +x /etc/systemd/system/pm2-thelounge.service
[DONE]
>>> Executing systemctl enable pm2-thelounge
[DONE]
>>> Executing systemctl start pm2-thelounge
Job for pm2-thelounge.service failed because of unavailable resources or another system error.
See "systemctl status pm2-thelounge.service" and "journalctl -xe" for details.
[ERROR] Exit code : 1
[PM2][ERROR] systemctl start pm2-thelounge failed, see error above.
Jun 11 03:06:56 server systemd[1]: Starting PM2 process manager...
-- Subject: Unit pm2-thelounge.service has begun start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit pm2-thelounge.service has begun starting up.
Jun 11 03:06:58 server pm2[31767]: [PM2] Spawning PM2 daemon with pm2_home=/home/thelounge/.pm2
Jun 11 03:06:59 server systemd[1]: pm2-thelounge.service: PID file /home/thelounge/.pm2/pm2.pid not readable (yet?) after start: No such file or directory
Jun 11 03:06:59 server systemd[1]: Failed to start PM2 process manager.
-- Subject: Unit pm2-thelounge.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit pm2-thelounge.service has failed.
--
-- The result is failed.
Jun 11 03:06:59 server systemd[1]: pm2-thelounge.service: Unit entered failed state.
Jun 11 03:06:59 server systemd[1]: pm2-thelounge.service: Failed with result 'resources'.
Starting the App via "pm2 start xyz" also results in an error.
root@server:~# su thelounge -c 'pm2 start lounge -- start'
[PM2] Spawning PM2 daemon with pm2_home=/home/thelounge/.pm2
internal/child_process.js:319
throw errnoException(err, 'spawn');
^
Error: spawn EACCES
at exports._errnoException (util.js:1034:11)
at ChildProcess.spawn (internal/child_process.js:319:11)
at Object.exports.spawn (child_process.js:378:9)
at module.exports.Client.launchDaemon (/usr/local/lib/node_modules/pm2/lib/Client.js:230:40)
at /usr/local/lib/node_modules/pm2/lib/Client.js:102:10
at /usr/local/lib/node_modules/pm2/lib/Client.js:289:14
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)
PM2 version: `pm2 -v` 2.5.0
Node version: `node -v` v7.7.4
Windows? Mac? Linux? Ubuntu 17.04
Duplicate as https://github.com/Unitech/pm2/issues/2912
Thats what i though aswell, although editing said file, reloading systemctl daemon and then starting the service results in this:
thumper@server:~$ sudo systemctl daemon-reload
thumper@server:~$ sudo systemctl start pm2-thelounge.service
thumper@server:~$ systemctl status pm2-thelounge.service
* pm2-thelounge.service - PM2 process manager
Loaded: loaded (/etc/systemd/system/pm2-thelounge.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Sun 2017-06-11 15:10:57 CEST; 1s ago
Docs: https://pm2.keymetrics.io/
Process: 27342 ExecStop=/usr/local/lib/node_modules/pm2/bin/pm2 kill (code=exited, status=0/SUCCESS)
Process: 27308 ExecStart=/usr/local/lib/node_modules/pm2/bin/pm2 resurrect (code=exited, status=0/SUCC
Main PID: 27308 (code=exited, status=0/SUCCESS)
CPU: 1.071s
thumper@server:~$ sudo su thelounge -c 'pm2 start lounge -- start'
[PM2] Spawning PM2 daemon with pm2_home=/home/thelounge/.pm2
thumper@server:~$ sudo su thelounge -c 'pm2 status'
[PM2] Spawning PM2 daemon with pm2_home=/home/thelounge/.pm2
And
Journal -xe
Jun 11 15:12:28 server systemd[1]: Started PM2 process manager.
-- Subject: Unit pm2.service has finished start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit pm2.service has finished starting up.
--
-- The start-up result is done.
Jun 11 15:12:28 server pm2[28050]: pm2 launched in no-daemon mode (you can add DEBUG="*" env variable to get more messages)
Jun 11 15:12:28 server pm2[28050]: fs.js:584
Jun 11 15:12:28 server pm2[28050]: return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
Jun 11 15:12:28 server pm2[28050]: ^
Jun 11 15:12:28 server pm2[28050]: Error: EACCES: permission denied, open '/usr/local/lib/node_modules/pm2/node_modules/array-unique/index.js'
Jun 11 15:12:28 server pm2[28050]: at Object.fs.openSync (fs.js:584:18)
Jun 11 15:12:28 server pm2[28050]: at Object.fs.readFileSync (fs.js:491:33)
Jun 11 15:12:28 server pm2[28050]: at Object.Module._extensions..js (module.js:579:20)
Jun 11 15:12:28 server pm2[28050]: at Module.load (module.js:488:32)
Jun 11 15:12:28 server pm2[28050]: at tryModuleLoad (module.js:447:12)
Jun 11 15:12:28 server pm2[28050]: at Function.Module._load (module.js:439:3)
Jun 11 15:12:28 server pm2[28050]: at Module.require (module.js:498:17)
Jun 11 15:12:28 server pm2[28050]: at require (internal/module.js:20:19)
Jun 11 15:12:28 server pm2[28050]: at Object.<anonymous> (/usr/local/lib/node_modules/pm2/node_modules/micromatch/lib/utils.js:13:16)
Jun 11 15:12:28 server pm2[28050]: at Module._compile (module.js:571:32)
Jun 11 15:12:28 server systemd[1]: pm2.service: Main process exited, code=exited, status=1/FAILURE
Jun 11 15:12:29 server pm2[28080]: [PM2] Spawning PM2 daemon with pm2_home=/home/thelounge/.pm2
Jun 11 15:12:29 server systemd[1]: pm2.service: Unit entered failed state.
Jun 11 15:12:29 server systemd[1]: pm2.service: Failed with result 'exit-code'.
Jun 11 15:12:37 server systemd[1]: pm2.service: Service hold-off time over, scheduling restart.
Jun 11 15:12:37 server systemd[1]: Stopped PM2 process manager.
-- Subject: Unit pm2.service has finished shutting down
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit pm2.service has finished shutting down.
Jun 11 15:12:37 server systemd[1]: Started PM2 process manager.
-- Subject: Unit pm2.service has finished start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit pm2.service has finished starting up.
--
-- The start-up result is done.
Jun 11 15:12:38 server pm2[28117]: pm2 launched in no-daemon mode (you can add DEBUG="*" env variable to get more messages)
Jun 11 15:12:38 server pm2[28117]: fs.js:584
Jun 11 15:12:38 server pm2[28117]: return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
Jun 11 15:12:38 server pm2[28117]: ^
Jun 11 15:12:38 server pm2[28117]: Error: EACCES: permission denied, open '/usr/local/lib/node_modules/pm2/node_modules/array-unique/index.js'
Jun 11 15:12:38 server pm2[28117]: at Object.fs.openSync (fs.js:584:18)
Jun 11 15:12:38 server pm2[28117]: at Object.fs.readFileSync (fs.js:491:33)
Jun 11 15:12:38 server pm2[28117]: at Object.Module._extensions..js (module.js:579:20)
Jun 11 15:12:38 server pm2[28117]: at Module.load (module.js:488:32)
Jun 11 15:12:38 server pm2[28117]: at tryModuleLoad (module.js:447:12)
Jun 11 15:12:38 server pm2[28117]: at Function.Module._load (module.js:439:3)
Jun 11 15:12:38 server pm2[28117]: at Module.require (module.js:498:17)
Jun 11 15:12:38 server pm2[28117]: at require (internal/module.js:20:19)
Jun 11 15:12:38 server pm2[28117]: at Object.<anonymous> (/usr/local/lib/node_modules/pm2/node_modules/micromatch/lib/utils.js:13:16)
Jun 11 15:12:38 server pm2[28117]: at Module._compile (module.js:571:32)
Jun 11 15:12:38 server systemd[1]: pm2.service: Main process exited, code=exited, status=1/FAILURE
Jun 11 15:12:38 server pm2[28137]: [PM2] Spawning PM2 daemon with pm2_home=/home/thelounge/.pm2
Jun 11 15:12:38 server systemd[1]: pm2.service: Unit entered failed state.
Jun 11 15:12:38 server systemd[1]: pm2.service: Failed with result 'exit-code'.
Which modification you made ?
PS : Your error may come from https://github.com/npm/npm/issues/16896
That might be the issue, as i cant seem to start anything node related anymore. I'll purge & reinstall.
Feature added in upcoming PM2. To try it:
(Make sure pm2 is run as root to manipulate uid and gid)
$ pm2 save
$ pm2 kill
$ npm install Unitech/pm2#development -g
$ sudo pm2 resurrect
$ sudo pm2 start app --uid <uid>
# Now pm2 ls display the user running the script
$ pm2 ls
Feedback is welcome
@Thumpxr Are you under root folder when executing pm2? Try to execute pm2 status under the user's home folder:
cd ~
pm2 status
Most helpful comment
@Thumpxr Are you under
rootfolder when executingpm2? Try to executepm2 statusunder the user's home folder: