Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular dspace doesn't start with pm2 after reboot #2495

Closed
RichardCBravo opened this issue Sep 13, 2023 · 5 comments
Closed

Angular dspace doesn't start with pm2 after reboot #2495

RichardCBravo opened this issue Sep 13, 2023 · 5 comments
Labels
bug cannot reproduce Unable to reproduce at this time, so the ticket either needs more information or needs closing

Comments

@RichardCBravo
Copy link

RichardCBravo commented Sep 13, 2023

Describe the bug
The error arises when the entire process is done to leave pm2 as a service, when restarting this error starts to appear:

/home/dspace/.pm2/logs/dspace-angular-1.log last 15 lines:

1|dspace-f | "),__name(clientSideRender,"clientSideRender"),__name(addCacheControl,"addCacheControl"),__name(initCache,"initCache"),__name(botCacheEnabled,"botCacheEnabled"),__name(anonymousCacheEnabled,"anonymousCacheEnabled"),__name(cacheCheck,"cacheCheck"),__name(checkCacheForRequest,"checkCacheForRequest"),__name(getCacheKey,"getCacheKey"),__name(saveToCache,"saveToCache"),__name(hasNotSucceeded,"hasNotSucceeded"),__name(retrieveHeaders,"retrieveHeaders"),__name(isUserAuthenticated,"isUserAuthenticated"),__name(serverStarted,"serverStarted"),__name(createHttpsServer,"createHttpsServer"),__name(run,"run"),__name(start,"start"),__name(healthCheck,"healthCheck");const mainModule=require.main,moduleFilename=mainModule&&mainModule.filename||"";(moduleFilename===__filename||moduleFilename.includes("iisnode"))&&start()})();var __webpack_export_target__=exports;for(var i in __webpack_exports__)__webpack_export_target__[i]=__webpack_exports__[i];__webpack_exports__.__esModule&&Object.defineProperty(__webpack_export_target__,"__esModule",{value:!0})})();


0|dspace-f | 
0|dspace-f | SyntaxError: Unexpected token '.'
0|dspace-f |     at wrapSafe (internal/modules/cjs/loader.js:915:16)
0|dspace-f |     at Module._compile (internal/modules/cjs/loader.js:963:27)
0|dspace-f |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
0|dspace-f |     at Module.load (internal/modules/cjs/loader.js:863:32)
0|dspace-f |     at Function.Module._load (internal/modules/cjs/loader.js:708:14)
0|dspace-f |     at /home/dspace/.nvm/versions/node/v18.16.0/lib/node_modules/pm2/lib/ProcessContainer.js:303:25
0|dspace-f |     at wrapper (/home/dspace/.nvm/versions/node/v18.16.0/lib/node_modules/pm2/node_modules/async/internal/once.js:12:16)
0|dspace-f |     at next (/home/dspace/.nvm/versions/node/v18.16.0/lib/node_modules/pm2/node_modules/async/waterfall.js:96:20)
0|dspace-f |     at /home/dspace/.nvm/versions/node/v18.16.0/lib/node_modules/pm2/node_modules/async/internal/onlyOnce.js:12:16
0|dspace-f |     at WriteStream.<anonymous> (/home/dspace/.nvm/versions/node/v18.16.0/lib/node_modules/pm2/lib/Utility.js:186:13)

dspace-angular.json:

{
  "apps": [
    {
      "name": "dspace-siete",
      "cwd": "/home/dspace/dspace-angular",
      "script": "dist/server/main.js",
      "max_memory_restart": "1024M",
      "env": {
        "NODE_ENV": "production"
      },
      "instances": 4,
      "exec_mode": "cluster",
      "node_args": "--max_old_space_size=4096"
    }
  ]
}

To Reproduce
Steps to reproduce the behavior:
All commands with dspace user

  1. git clone -b dspace-7.6 https://github.com/DSpace/dspace-angular.git
  2. yarn install
  3. yarn build:prod
  4. pm2 start dspace-angular.json
  5. pm2 startup
  6. root user => sudo env PATH=$PATH:/home/dspace/.nvm/versions/node/v18.17.1/bin /home/dspace/.nvm/versions/node/v18.17.1/lib/node_modules/pm2/bin/pm2 startup systemd -u dspace --hp /home/dspace
  7. dspace user pm2 save
  8. root user => reboot

Expected behavior
It should start Angular automatically.

@RichardCBravo RichardCBravo added bug needs triage New issue needs triage and/or scheduling labels Sep 13, 2023
@alanorth
Copy link
Contributor

alanorth commented Sep 23, 2023

This doesn't seem like a DSpace Angular bug to me. Can you try running the application manually on the command line without the JSON manifest? For example:

$ pm2 start ./dist/server/main.js --name dspace-ui -i 4

@RichardCBravo
Copy link
Author

The same error occurs with the command you're suggesting. Could it be the version of PM2? I'm using version 5.3.0, which is the latest.

I'll send the error again:

/home/dspace/.pm2/logs/dspace-ui-error-2.log last 15 lines:
2|dspace-u | "),__name(clientSideRender,"clientSideRender"),__name(addCacheControl,"addCacheControl"),__name(initCache,"initCache"),__name(botCacheEnabled,"botCacheEnabled"),__name(anonymousCacheEnabled,"anonymousCacheEnabled"),__name(cacheCheck,"cacheCheck"),__name(checkCacheForRequest,"checkCacheForRequest"),__name(getCacheKey,"getCacheKey"),__name(saveToCache,"saveToCache"),__name(hasNotSucceeded,"hasNotSucceeded"),__name(retrieveHeaders,"retrieveHeaders"),__name(isUserAuthenticated,"isUserAuthenticated"),__name(serverStarted,"serverStarted"),__name(createHttpsServer,"createHttpsServer"),__name(run,"run"),__name(start,"start"),__name(healthCheck,"healthCheck");const mainModule=require.main,moduleFilename=mainModule&&mainModule.filename||"";(moduleFilename===__filename||moduleFilename.includes("iisnode"))&&start()})();var webpack_export_target=exports;for(var i in webpack_exports)webpack_export_target[i]=webpack_exports[i];webpack_exports.__esModule&&Object.defineProperty(webpack_export_target,"__esModule",{value:!0})})();
2|dspace-u |
2|dspace-u |
2|dspace-u | SyntaxError: Unexpected token '.'
2|dspace-u | at wrapSafe (internal/modules/cjs/loader.js:915:16)
2|dspace-u | at Module._compile (internal/modules/cjs/loader.js:963:27)
2|dspace-u | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
2|dspace-u | at Module.load (internal/modules/cjs/loader.js:863:32)
2|dspace-u | at Function.Module._load (internal/modules/cjs/loader.js:708:14)
2|dspace-u | at /home/dspace/.nvm/versions/node/v18.17.1/lib/node_modules/pm2/lib/ProcessContainer.js:304:25
2|dspace-u | at wrapper (/home/dspace/.nvm/versions/node/v18.17.1/lib/node_modules/pm2/node_modules/async/internal/once.js:12:16)
2|dspace-u | at next (/home/dspace/.nvm/versions/node/v18.17.1/lib/node_modules/pm2/node_modules/async/waterfall.js:96:20)
2|dspace-u | at /home/dspace/.nvm/versions/node/v18.17.1/lib/node_modules/pm2/node_modules/async/internal/onlyOnce.js:12:16
2|dspace-u | at WriteStream. (/home/dspace/.nvm/versions/node/v18.17.1/lib/node_modules/pm2/lib/Utility.js:186:13)

@alanorth
Copy link
Contributor

This is working for me on DSpace 7.6:

$ pm2 start ./dist/server/main.js --name dspace-ui -i 4

PM2 version 5.3.0 is correct. I think the SyntaxError in your error is suspicious. Is your manifest correct? Also, try removing the node_modules and doing yarn install again—maybe something is corrupt or out of date.

@RichardCBravo
Copy link
Author

It keeps giving me the same error with:
$ pm2 start ./dist/server/main.js --name dspace-ui -i 4
$ pm2 save
$ pm2 startup
$ reboot

Also when I generate the crontab that executes a .sh I start it as soon as I restart, I have to add a waiting time of about 2 minutes so that the error does not occur, I add it as follows:

dspace.sh:

#!/bin/bash

#PM2
PM2="/home/dspace/.nvm/versions/node/v18.17.1/bin/pm2"
#dspace-deploy
cd /home/dspace/dspace-deploy
sleep 120
$PM2 start dspace-angular.json

exit

If I remove 'sleep', the same error appears.

I don't do any $ pm2 save or $ pm2 startup because they are the ones that give me the problem.

@tdonohue
Copy link
Member

tdonohue commented Oct 4, 2023

@RichardCBravo : I agree with @alanorth that this doesn't seem like a DSpace issue. It sounds like something is wrong with your PM2 installation, or maybe you didn't install it globally?

I see there's a variety of issues reported to PM2's own ticketing system that say things like "SyntaxError: Unexpected token" (which is the error you see). They seem to all be related to either PM2 is using an invalid version of Node.js, or PM2 itself wasn't installed properly. Here's one such example: Unitech/pm2#4588

I'd recommend trying to reinstall PM2 if possible. It sounds, to me, like your PM2 isn't working at all... but correct me if I'm wrong. It doesn't sound like the issue is specific to rebooting your machine.

Overall, I'd recommend moving this discussion to one of our Support options at https://wiki.lyrasis.org/display/DSPACE/Support We only recommend creating tickets like this for bugs in DSpace. This sounds like it's either a bug in PM2, or a misconfiguration or bad installation of PM2. Using those Support options (especially mailing lists) can also get advice from many other DSpace users...and it's always possible one of them has seen this error before.

Closing this as it doesn't seem to be a bug in DSpace itself. Not able to reproduce this myself & others have not either.

@tdonohue tdonohue closed this as not planned Won't fix, can't repro, duplicate, stale Oct 4, 2023
@tdonohue tdonohue added cannot reproduce Unable to reproduce at this time, so the ticket either needs more information or needs closing and removed needs triage New issue needs triage and/or scheduling labels Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cannot reproduce Unable to reproduce at this time, so the ticket either needs more information or needs closing
Projects
Status: Done / Closed
Development

No branches or pull requests

3 participants