To use this function add it to the class library file named PluginVCHostSystemService.ts
GitHub Repository: https://github.com/SimonSparksUK/Orchestrator
Filename: PluginVCHostSystemService.ts
Public Function: ServiceStart
publicServiceStart(objVcHostSystem:VcHostSystem,strServiceName:string):boolean{
letblnReturn:boolean=this.ServiceToggle(objVcHostSystem,strServiceName,"Start");
returnblnReturn;
}TypeScriptPublic Function: ServiceStop
publicServiceStop(objVcHostSystem:VcHostSystem,strServiceName:string):boolean{
letblnReturn:boolean=this.ServiceToggle(objVcHostSystem,strServiceName,"Stop");
returnblnReturn;
}TypeScriptPublic Function: ServiceRestart
publicServiceRestart(objVcHostSystem:VcHostSystem,strServiceName:string):boolean{
letblnReturn:boolean=this.ServiceToggle(objVcHostSystem,strServiceName,"Restart");
returnblnReturn;
}TypeScriptPrivate Function: ServiceToggle
privateServiceToggle(objVcHostSystem:VcHostSystem,strServiceName:string,strServiceStatus:"Start"|"Stop"|"Restart"):boolean{
try{
letobjVcHostConfigManager:VcHostConfigManager=objVcHostSystem.configManager;
letobjVcHostServiceSystem:VcHostServiceSystem=objVcHostConfigManager.serviceSystem;
letobjVcHostService:VcHostService=this.ServiceGetByName(objVcHostServiceSystem,strServiceName);
this.objLogger.info(`Attempting to${strServiceStatus} Service on host: '${objVcHostSystem.name}'...`);
if (objVcHostService.running===true&&strServiceStatus==="Restart"){
objVcHostServiceSystem.restartService(strServiceName);
}elseif (objVcHostService.running===true&&strServiceStatus==="Stop"){
objVcHostServiceSystem.stopService(strServiceName);
}elseif (objVcHostService.running===false&&strServiceStatus==="Start"){
objVcHostServiceSystem.startService(strServiceName);
}
this.objLogger.info(`Succesfully${strServiceStatus}ed Service on host: '${objVcHostSystem.name}'.`);
returntrue;
}
catch (objException){
this.objLogger.info(`Failed to${strServiceStatus} Service on host: '${objVcHostSystem.name}'.`);
returnfalse;
}
}TypeScriptDiscover more from Cloud Build Tools
Subscribe to get the latest posts sent to your email.
