【问题标题】:How to keep a process alive after remote PowerShell script completion?远程 PowerShell 脚本完成后如何使进程保持活动状态?
【发布时间】:2016-09-26 11:54:43
【问题描述】:

我正在尝试通过 PowerShell 脚本块远程启动 Zookeeper 和 Solr。 然后我看到该进程是在远程机器中创建的(通过检查Zookeeper的2181端口)。并且在脚本完成时它被终止。 即使在完成后如何保持它的存在?

以下代码在脚本完成时停止远程进程。 script.ps1 做了很多事情,包括启动 Zookeeper 和 Solr 作为Job。

int iRemotePort = 5985;
string strShellURI = @"http://schemas.microsoft.com/powershell/Microsoft.PowerShell";
string strAppName = @"/wsman";
WSManConnectionInfo ci = new WSManConnectionInfo(
    false,
    machineName,
    iRemotePort,
    strAppName,
    strShellURI,
    new PSCredential(userName, secure));

Runspace runspace = RunspaceFactory.CreateRunspace(ci);
runspace.Open();
using (PowerShell ps = PowerShell.Create())
{
    session.Log(@"c:\temp\script.ps1 -serverID " + counter + " -copySolrConfig $" + status + " -currentHost \"" + machineName + "\" -IP_PORT_List \"" + String.Join(", ", machineWithPort) + "\"");
    ps.Runspace = runspace;
    ps.AddScript(@"c:\temp\script.ps1 -serverID " + counter + " -copySolrConfig $" + status + " -currentHost \"" + machineName + "\" -IP_PORT_List \"" + String.Join(", ", machineWithPort) + "\"");

    var results = ps.Invoke();

    foreach (var result in results)
    {
        session.Log(result.ToString());
    }
}
runspace.Close();

【问题讨论】:

  • 有关您的代码的帮助:显示您的代码。

标签: c# powershell solr apache-zookeeper


【解决方案1】:

所以经过长时间的尝试,我得出一个结论,使用 power-shell script alive 不是保持 zookeeper 和 solr 有效运行的合适方法。因此将其作为 Windows 服务移动并通过 WiX 将其安装在远程计算机上。

【讨论】:

    猜你喜欢
    • 2011-10-19
    • 2022-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-16
    • 1970-01-01
    相关资源
    最近更新 更多