mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-17 19:14:40 +01:00
CLOUDSTACK-5657: Run the service as an account (hyper-v admin on host) so
that migration can work across hosts.
This commit is contained in:
parent
db2b025608
commit
641f85cf6f
@ -29,7 +29,13 @@ namespace CloudStack.Plugin.AgentShell
|
|||||||
static class Program
|
static class Program
|
||||||
{
|
{
|
||||||
private static ILog logger = LogManager.GetLogger(typeof(Program));
|
private static ILog logger = LogManager.GetLogger(typeof(Program));
|
||||||
public static string serviceName = "CloudStack Hyper-V Agent";
|
public const string serviceName = "CloudStack Hyper-V Agent";
|
||||||
|
private static string option = null;
|
||||||
|
private static string user = null;
|
||||||
|
private static string password = null;
|
||||||
|
private const string install = "--install";
|
||||||
|
private const string uninstall = "--uninstall";
|
||||||
|
private const string console = "--console";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Application entry point allows service to run in console application or as a Windows service.
|
/// Application entry point allows service to run in console application or as a Windows service.
|
||||||
@ -43,22 +49,21 @@ namespace CloudStack.Plugin.AgentShell
|
|||||||
ServiceBase[] ServicesToRun = new ServiceBase[] { new AgentService() };
|
ServiceBase[] ServicesToRun = new ServiceBase[] { new AgentService() };
|
||||||
ServiceBase.Run(ServicesToRun);
|
ServiceBase.Run(ServicesToRun);
|
||||||
}
|
}
|
||||||
else if (args.Length == 1)
|
else if (ParseArguments(args))
|
||||||
{
|
{
|
||||||
logger.DebugFormat(serviceName + " arg is ", args[0]);
|
switch (option)
|
||||||
switch (args[0])
|
|
||||||
{
|
{
|
||||||
case "--install":
|
case install:
|
||||||
logger.InfoFormat("Installing and running " + serviceName);
|
logger.InfoFormat("Installing and running " + serviceName);
|
||||||
InstallService();
|
InstallService();
|
||||||
StartService();
|
StartService();
|
||||||
break;
|
break;
|
||||||
case "--uninstall":
|
case uninstall:
|
||||||
logger.InfoFormat("Stopping and uninstalling " + serviceName);
|
logger.InfoFormat("Stopping and uninstalling " + serviceName);
|
||||||
StopService();
|
StopService();
|
||||||
UninstallService();
|
UninstallService();
|
||||||
break;
|
break;
|
||||||
case "--console":
|
case console:
|
||||||
logger.InfoFormat(serviceName + " is running as console application");
|
logger.InfoFormat(serviceName + " is running as console application");
|
||||||
new AgentService().RunConsole(args);
|
new AgentService().RunConsole(args);
|
||||||
break;
|
break;
|
||||||
@ -66,6 +71,74 @@ namespace CloudStack.Plugin.AgentShell
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string argumentExample = "--(install/uninstall/console) [-u <hyper-v admin user>] [-p <hyper-v admin password>].\n" +
|
||||||
|
" For example:\n " +
|
||||||
|
" --install -u domain1\\user1 -p mypwd\n"+
|
||||||
|
" --uninstall";
|
||||||
|
logger.Error("Invalid arguments passed for installing\\uninstalling the service. \n" + argumentExample);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static private Boolean ParseArguments(string[] args)
|
||||||
|
{
|
||||||
|
logger.DebugFormat(serviceName + " arg is ", args[0]);
|
||||||
|
int argIndex = 0;
|
||||||
|
while (argIndex < args.Length)
|
||||||
|
{
|
||||||
|
switch (args[argIndex])
|
||||||
|
{
|
||||||
|
case install:
|
||||||
|
case uninstall:
|
||||||
|
case console:
|
||||||
|
option = args[argIndex];
|
||||||
|
argIndex++;
|
||||||
|
break;
|
||||||
|
case "-u":
|
||||||
|
user = args[argIndex+1];
|
||||||
|
argIndex+=2;
|
||||||
|
break;
|
||||||
|
case "-p":
|
||||||
|
password = args[argIndex+1];
|
||||||
|
argIndex+=2;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
argIndex++;
|
||||||
|
// Unrecognised argument. Do nothing;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate arguments
|
||||||
|
return ValidateArguments();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Boolean ValidateArguments()
|
||||||
|
{
|
||||||
|
Boolean argsValid = false;
|
||||||
|
switch (option)
|
||||||
|
{
|
||||||
|
case uninstall:
|
||||||
|
case install:
|
||||||
|
case console:
|
||||||
|
argsValid = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return argsValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetPassword()
|
||||||
|
{
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetUser()
|
||||||
|
{
|
||||||
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsInstalled()
|
private static bool IsInstalled()
|
||||||
|
|||||||
@ -49,9 +49,22 @@ namespace CloudStack.Plugin.AgentShell
|
|||||||
//
|
//
|
||||||
// serviceProcessInstaller
|
// serviceProcessInstaller
|
||||||
//
|
//
|
||||||
|
string user = Program.GetUser();
|
||||||
|
string password = Program.GetPassword();
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(user))
|
||||||
|
{
|
||||||
this.serviceProcessInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
|
this.serviceProcessInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
|
||||||
this.serviceProcessInstaller.Password = null;
|
this.serviceProcessInstaller.Password = null;
|
||||||
this.serviceProcessInstaller.Username = null;
|
this.serviceProcessInstaller.Username = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.serviceProcessInstaller.Account = System.ServiceProcess.ServiceAccount.User;
|
||||||
|
this.serviceProcessInstaller.Password = password;
|
||||||
|
this.serviceProcessInstaller.Username = user;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// serviceInstaller
|
// serviceInstaller
|
||||||
//
|
//
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user