How to write startup command in nodejs App Service (Stack: node20 LTS OS:Linux)?
We need to install pm2-logrotate module in webapp, however the webapp can't start when input startup command in App Service. Could you please help to confirm how to write the start command in nodejs webapp and let the webapp start successfully?
Error screenshot : If we don't input start command in webapp, the webapp can start successfully.
Start command: install pm2-logrotate module
Doker log:
2024-07-11T15:24:33.300Z INFO - Starting container for site
2024-07-11T15:24:33.301Z INFO - docker run -d --expose=8080 --name nodejs0711_0_3d6f0176 -e WEBSITE_USE_DIAGNOSTIC_SERVER=true -e WEBSITE_SITE_NAME=nodejs0711 -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=nodejs0711.chinacloudsites.cn -e WEBSITE_INSTANCE_ID=37c77572be775c3da9e718e75bdd3dcd6c69246656e6f77972070ce4bfef6455 appsvc/node:20-lts_20240619.2.tuxprod pm2 install pm2-logrotate
2024-07-11T15:24:33.302Z INFO - Logging is not enabled for this container.
Please use https://aka.ms/linux-diagnostics to enable logging to see container logs here.
2024-07-11T15:24:36.378Z INFO - Initiating warmup request to container nodejs0711_0_3d6f0176 for site nodejs0711
2024-07-11T15:24:53.479Z INFO - Waiting for response to warmup request for container nodejs0711_0_3d6f0176. Elapsed time = 17.1014129 sec
2024-07-11T15:25:09.013Z INFO - Waiting for response to warmup request for container nodejs0711_0_3d6f0176. Elapsed time = 32.6347812 sec
2024-07-11T15:25:24.567Z INFO - Waiting for response to warmup request for container nodejs0711_0_3d6f0176. Elapsed time = 48.1890842 sec
2024-07-11T15:25:40.122Z INFO - Waiting for response to warmup request for container nodejs0711_0_3d6f0176. Elapsed time = 63.7435066 sec
2024-07-11T15:25:54.622Z ERROR - Container nodejs0711_0_3d6f0176 for site nodejs0711 has exited, failing site start
2024-07-11T15:25:54.643Z ERROR - Container nodejs0711_0_3d6f0176 didn't respond to HTTP pings on port: 8080, failing site start. See container logs for debugging.
2024-07-11T15:25:54.714Z INFO - Stopping site nodejs0711 because it failed during startup.
Default docker log: we can see the pm2-logrotate module was installed successfully.
2024-07-11T15:24:34.303085997Z _____
2024-07-11T15:24:34.303142997Z / _ \ __________ _________ ____
2024-07-11T15:24:34.303149297Z / /\ \__ / | _ __ _/ __ \
2024-07-11T15:24:34.303153097Z / | / /| | /| | /\ ___/
2024-07-11T15:24:34.303156597Z _| /_____ _/ || ___ >
2024-07-11T15:24:34.303160297Z / / /
2024-07-11T15:24:34.303163697Z A P P S E R V I C E O N L I N U X
2024-07-11T15:24:34.303167197Z
2024-07-11T15:24:34.303170597Z Documentation: http://aka.ms/webapp-linux
2024-07-11T15:24:34.303173897Z NodeJS quickstart: https://aka.ms/node-qs
2024-07-11T15:24:34.303177197Z NodeJS Version : v20.14.0
2024-07-11T15:24:34.303180497Z Note: Any data outside '/home' is not persisted
2024-07-11T15:24:34.303184697Z
2024-07-11T15:24:39.240284014Z Starting OpenBSD Secure Shell server: sshd.
2024-07-11T15:24:39.299857429Z WEBSITES_INCLUDE_CLOUD_CERTS is not set to true.
2024-07-11T15:24:39.816415227Z Starting periodic command scheduler: cron.
2024-07-11T15:24:40.143405158Z Could not find build manifest file at '/home/site/wwwroot/oryx-manifest.toml'
2024-07-11T15:24:40.145019161Z Could not find operation ID in manifest. Generating an operation id...
2024-07-11T15:24:40.145039361Z Build Operation ID: 3493ae99-b7d4-40b1-916b-aa04a3f58819
2024-07-11T15:24:42.293290080Z Environment Variables for Application Insight's IPA Codeless Configuration exists..
2024-07-11T15:24:42.518576910Z Writing output script to '/opt/startup/startup.sh'
2024-07-11T15:24:42.795027137Z Running #!/bin/sh
2024-07-11T15:24:42.795077737Z
2024-07-11T15:24:42.795084137Z # Enter the source directory to make sure the script runs where the user expects
2024-07-11T15:24:42.795088537Z cd "/home/site/wwwroot"
2024-07-11T15:24:42.795092537Z
2024-07-11T15:24:42.795096337Z export NODE_PATH=/usr/local/lib/node_modules:$NODE_PATH
2024-07-11T15:24:42.795100337Z if [ -z "$PORT" ]; then
2024-07-11T15:24:42.795104337Z export PORT=8080
2024-07-11T15:24:42.795108437Z fi
2024-07-11T15:24:42.795113037Z
2024-07-11T15:24:42.795116837Z PATH="$PATH:/home/site/wwwroot" pm2 install pm2-logrotate
2024-07-11T15:24:46.745956269Z
2024-07-11T15:24:46.746033770Z -------------
2024-07-11T15:24:46.746042071Z
2024-07-11T15:24:46.746046971Z /\\\\\\_/\\___________/\\/\\\\_
2024-07-11T15:24:46.746052471Z _/\/////////\_/\\\____/\\\/\///////\_
2024-07-11T15:24:46.746058071Z /\_/\_/\//\_/\//\_///___//\_
2024-07-11T15:24:46.746083171Z /\\\\\\/__/\\///\/\//\________/\/
2024-07-11T15:24:46.746089971Z /\//////////\_///\//\__/\//
2024-07-11T15:24:46.746095071Z /\_/\_////\__/\//________
2024-07-11T15:24:46.746100171Z /\_/\_/\_/\/________
2024-07-11T15:24:46.746104971Z /\_/\_/\_/\\\\\\\_
2024-07-11T15:24:46.746110072Z _////////////////////////
2024-07-11T15:24:46.746114772Z
2024-07-11T15:24:46.746119372Z
2024-07-11T15:24:46.746123772Z Runtime Edition
2024-07-11T15:24:46.746128272Z
2024-07-11T15:24:46.746132672Z PM2 is a Production Process Manager for Node.js applications
2024-07-11T15:24:46.746137272Z with a built-in Load Balancer.
2024-07-11T15:24:46.746141872Z
2024-07-11T15:24:46.746146172Z Start and Daemonize any application:
2024-07-11T15:24:46.746150772Z $ pm2 start app.js
2024-07-11T15:24:46.746155272Z
2024-07-11T15:24:46.746159672Z Load Balance 4 instances of api.js:
2024-07-11T15:24:46.746164172Z $ pm2 start api.js -i 4
2024-07-11T15:24:46.746168672Z
2024-07-11T15:24:46.746173072Z Monitor in production:
2024-07-11T15:24:46.746177873Z $ pm2 monitor
2024-07-11T15:24:46.746182373Z
2024-07-11T15:24:46.746186673Z Make pm2 auto-boot at server restart:
2024-07-11T15:24:46.746191273Z $ pm2 startup
2024-07-11T15:24:46.746195773Z
2024-07-11T15:24:46.746200073Z To go further checkout:
2024-07-11T15:24:46.746204473Z http://pm2.io/
2024-07-11T15:24:46.746208973Z
2024-07-11T15:24:46.746213273Z
2024-07-11T15:24:46.746217673Z -------------
2024-07-11T15:24:46.746222173Z
2024-07-11T15:24:46.960528992Z [PM2] Spawning PM2 daemon with pm2_home=/root/.pm2
2024-07-11T15:24:48.159437444Z [PM2] This PM2 is not UP TO DATE
2024-07-11T15:24:48.254012303Z [PM2] Upgrade to version 5.4.2
2024-07-11T15:24:49.460544609Z [PM2] PM2 Successfully daemonized
2024-07-11T15:24:49.557142264Z [PM2][Module] Installing NPM pm2-logrotate module
2024-07-11T15:24:49.686806771Z [PM2][Module] Calling [NPM] to install pm2-logrotate ...
2024-07-11T15:25:52.906496053Z
2024-07-11T15:25:52.914779470Z added 178 packages in 1m
2024-07-11T15:25:52.925089790Z
2024-07-11T15:25:52.925114590Z 22 packages are looking for funding
2024-07-11T15:25:52.925120290Z run npm fund
for details
2024-07-11T15:25:52.934718610Z npm notice
2024-07-11T15:25:52.936759714Z npm notice New minor version of npm available! 10.5.0 -> 10.8.2
2024-07-11T15:25:52.943107326Z npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.8.2
2024-07-11T15:25:52.952904546Z npm notice Run npm install -g npm@10.8.2
to update!
2024-07-11T15:25:52.952965946Z npm notice
2024-07-11T15:25:53.035646011Z [PM2][Module] Module downloaded
2024-07-11T15:25:53.080548800Z [PM2][WARN] Applications pm2-logrotate not running, starting...
2024-07-11T15:25:53.188017714Z [PM2] App [pm2-logrotate] launched (1 instances)
2024-07-11T15:25:53.197364433Z Module: pm2-logrotate
2024-07-11T15:25:53.197985334Z $ pm2 set pm2-logrotate:max_size 10M
2024-07-11T15:25:53.199967838Z $ pm2 set pm2-logrotate:retain 30
2024-07-11T15:25:53.206671551Z $ pm2 set pm2-logrotate:compress false
2024-07-11T15:25:53.208114954Z $ pm2 set pm2-logrotate:dateFormat YYYY-MM-DD_HH-mm-ss
2024-07-11T15:25:53.208132554Z $ pm2 set pm2-logrotate:workerInterval 30
2024-07-11T15:25:53.208453355Z **$ pm2 set pm2-logrotate:rotateInterval 0 0 * * ***
2024-07-11T15:25:53.209702557Z $ pm2 set pm2-logrotate:rotateModule true
2024-07-11T15:25:53.209722157Z Modules configuration. Copy/Paste line to edit values.
2024-07-11T15:25:53.217413973Z [PM2][Module] Module successfully installed and launched
2024-07-11T15:25:53.226902092Z [PM2][Module] Checkout module options: $ pm2 conf
2024-07-11T15:25:53.403106642Z ┌────┬──────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
2024-07-11T15:25:53.403164742Z │ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
2024-07-11T15:25:53.403173142Z └────┴──────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
2024-07-11T15:25:53.406698349Z Module
2024-07-11T15:25:53.433406102Z ┌────┬──────────────────────────────┬───────────────┬──────────┬──────────┬──────┬──────────┬──────────┬──────────┐
2024-07-11T15:25:53.433458903Z │ id │ module │ version │ pid │ status │ ↺ │ cpu │ mem │ user │
2024-07-11T15:25:53.433466003Z ├────┼──────────────────────────────┼───────────────┼──────────┼──────────┼──────┼──────────┼──────────┼──────────┤
2024-07-11T15:25:53.433470903Z │ 0 │ pm2-logrotate │ 2.7.0 │ 150 │ online │ 0 │ 0% │ 20.7mb │ root │
2024-07-11T15:25:53.433475703Z └────┴──────────────────────────────┴───────────────┴──────────┴──────────┴──────┴──────────┴──────────┴──────────┘