task scheduling to automate send email and start the pm2 services

%3CLINGO-SUB%20id%3D%22lingo-sub-1086734%22%20slang%3D%22en-US%22%3Etask%20scheduling%20to%20automate%20send%20email%20and%20start%20the%20pm2%20services%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1086734%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20created%20a%20website%20named%20%3CSTRONG%3Eabccompany.com%3C%2FSTRONG%3E%20and%20used%20a%20node%20js%20with%20pm2%20services.%20now%20I%20want%20to%20use%20task%20scheduled%20like%20that%20whenever%20my%20website%20goes%20down%20or%20services%20goes%20offline%20it%20checks%20for%20pm2%20status%20either%20it%20is%20%3CSTRONG%3Eonline%3C%2FSTRONG%3E%20or%20%3CSTRONG%3Eoffline%3C%2FSTRONG%3E%20in%20every%20%3CSTRONG%3Ex%20seconds%20or%20minutes%3C%2FSTRONG%3E%20and%20automatically%20sends%20an%20email%20to%20admin%20and%20starts%20the%20services%20so%20that%20there%20should%20not%20be%20any%20fault%20tolerance%20when%20anybody%20reached%20my%20website.%20I%20just%20want%20all%20this%20using%20%3CSTRONG%3EPower%20Shell%3C%2FSTRONG%3E%26nbsp%3Band%20%3CSTRONG%3Etask%20scheduler.%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20find%20any%20resolution%20related%20to%20my%20query%20then%20please%20reply%20me%20at%20%3CSTRONG%3Edpakagarwal737%40outlook.com%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1086734%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1125006%22%20slang%3D%22en-US%22%3ERe%3A%20task%20scheduling%20to%20automate%20send%20email%20and%20start%20the%20pm2%20services%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1125006%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F504837%22%20target%3D%22_blank%22%3E%40deepak216632160%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAre%20you%20looking%20for%20a%20starting%20point%20or%20a%20full%20solution%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%23Start%20your%20script%20with%20a%20test%20of%20services%3A%3C%2FP%3E%0A%3CP%3E%24Running%20%3D%20get-service%20w3svc%3C%2FP%3E%0A%3CP%3E%23Then%20do%20an%20If%2FElse%3C%2FP%3E%0A%3CP%3EIf%20(%24running.state%20-eq%20%22Running%22)%20%7B%7D%3CBR%20%2F%3EElse%20%7BStart-service%20w3svc%20%3B%20Send-mailmessage%20%3CLOOKUP%20this%3D%22%22%20cmdlet%3D%22%22%20and%3D%22%22%20provide%3D%22%22%20values%3D%22%22%20for%3D%22%22%20the%3D%22%22%20parameters%3D%22%22%3E%26nbsp%3B%20%7D%3C%2FLOOKUP%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

I have created a website named abccompany.com and used a node js with pm2 services. now I want to use task scheduled like that whenever my website goes down or services goes offline it checks for pm2 status either it is online or offline in every x seconds or minutes and automatically sends an email to admin and starts the services so that there should not be any fault tolerance when anybody reached my website. I just want all this using Power Shell and task scheduler.

 

If you find any resolution related to my query then please reply me at dpakagarwal737@outlook.com

1 Reply

@deepak216632160 

Are you looking for a starting point or a full solution?

 #Start your script with a test of services:

$Running = get-service w3svc

#Then do an If/Else

If ($running.state -eq "Running") {}
Else {Start-service w3svc ; Send-mailmessage <lookup this cmdlet and provide values for the parameters>  }