2017-02-27 1 views
1

Procrun을 사용하여 Windows 서비스로 Java 응용 프로그램 (.jar)을 만들었습니다. 이 서비스는 배치 (.bat) 파일을 사용하면 성공적으로 설치되고 실행됩니다. 하지만 나는 Windows PowerShell을 사용하여 동일한 서비스를 만드는이 요구 사항을 가지고있다.PowerShell에서 Procrun을 사용하여 만든 Windows 서비스를 시작하지 못했습니다.

PowerShell을 사용할 때 서비스가 설치되지만 서비스를 시작할 수 없습니다. Windows 이벤트 뷰어에서 "잘못된 기능"으로 표시됩니다. 이유가 무엇인지 말해 줄 수 있습니까?

주시면 감사하겠습니다 내가 Windows 서비스

[email protected]' 

--Description="$Description" 
--DisplayName="$DisplayName" 
--Install="$DAEMON" 
--Startup=auto 
--Type= 
--DependsOn= 
--Environment= 
--User= 
--Password= 
--ServiceUser= 
--ServicePassword= 
--LibraryPath= 
--JavaHome 
--Jvm=auto 
--JvmOptions=-Xmx1024M 
--Classpath=server.jar 
--JvmMs= 
--JvmMx= 
--JvmSs= 
--StartMode=jvm 
--StartImage= 
--StartPath= 
--StartClass=at.mrdevelopment.esl.server.Server 
--StartMethod=main 
--StartParams= 
--StopMode=jvm 
--StopImage= 
--StopPath= 
--StopClass=at.mrdevelopment.esl.server.ServerServiceStarter 
--StopMethod=stop 
--StopParams= 
--StopTimeout=120 
--LogPath=$LogPath 
--LogPrefix=$InstanceName 
--LogLevel=DEBUG 
--LogJniMessages= 
--StdOutput=auto 
--StdError=auto 
--PidFile=${InstanceName}.pid 
'@ 

에게 어떤 도움을 설치하는 PowerShell 스크립트에서 사용되는 문자열입니다.

이것은 내가 사용하는 PowerShell 스크립트입니다.

#region Parameters 
    [CmdletBinding(SupportsShouldProcess=$true)] 
param(
    [ValidateNotNullOrEmpty()] 
    [string]$Action="//IS" 
    , 
    [ValidateNotNullOrEmpty()] 
    [string]$ServiceName="//ESL_SERVICE" 
    , 
    [ValidateNotNullOrEmpty()] 
    [string]$DisplayName="ESL_SERVICE" 
    , 
    [ValidateNotNullOrEmpty()] 
    [string]$Description="ESL Service" 
    , 
    [ValidateNotNullOrEmpty()] 
    [string]$InstanceName="server.jar" 
    , 
    [ValidateNotNullOrEmpty()] 
    [string]$LogPath='C:\Apachelogs' 
    , 
    [string]$Pause=60 
) 
#endregion 

#region Main 

[email protected]' 

--Description="$Description" 
--DisplayName="$DisplayName" 
--Install="$DAEMON" 
--Startup=auto 
--Type= 
--DependsOn= 
--Environment= 
--User= 
--Password= 
--ServiceUser= 
--ServicePassword= 
--LibraryPath= 
--JavaHome 
--Jvm=auto 
--JvmOptions=-Xmx1024M 
--Classpath=server.jar 
--JvmMs= 
--JvmMx= 
--JvmSs= 
--StartMode=jvm 
--StartImage= 
--StartPath= 
--StartClass=at.mrdevelopment.esl.server.Server 
--StartMethod=main 
--StartParams= 
--StopMode=jvm 
--StopImage= 
--StopPath= 
--StopClass=at.mrdevelopment.esl.server.ServerServiceStarter 
--StopMethod=stop 
--StopParams= 
--StopTimeout=120 
--LogPath=$LogPath 
--LogPrefix=$InstanceName 
--LogLevel=DEBUG 
--LogJniMessages= 
--StdOutput=auto 
--StdError=auto 
--PidFile=${InstanceName}.pid 
'@ 

$DAEMON_HOME   = "C:\imagotag\server" 
$DAEMON    = "$DAEMON_HOME\prunsrv_64.exe"            
$ESL_HOME   = "C:\imagotag\server" 

[email protected]{} 

$CmdArgsDict.Add('//IS',  "$Action$ServiceName $CmdInstall") 

$CmdArgs    = $CmdArgsDict[$action] 
# Convert backslashes in the paths to java-friendly forward slashes 
$CmdArgs    = $CmdArgs -replace "\\","/" 
# Variable interpolation: expand embedded variables references (need to call this twice) 
$CmdArgs    = $ExecutionContext.InvokeCommand.ExpandString($CmdArgs) 
$CmdArgs    = $ExecutionContext.InvokeCommand.ExpandString($CmdArgs) 
# Split on newlines to convert to an array of lines 
$CmdArgsString  = $CmdArgs -split "`n" 
# Convert array of lines into a string 
$CmdArgsString  = "$CmdArgsString" 


#--- Execute the command 
if ($PSCmdlet.ShouldProcess(
    "`n$DAEMON`n$CmdArgs","Manage ESL Service" 
)) 
{ 
    "$DAEMON $CmdArgsString" 

    $p=Start-Process "$DAEMON" ` 
     -ArgumentList "$CmdArgsString" ` 
     -Wait ` 
     -NoNewWindow ` 
     -PassThru 

    $rc = $p.ExitCode 
    "`nExit Code: $rc" 
} 
#endregion 

내 PowerShell 스크립트가 TestPS.ps1 내가이 서비스를 만들기 위해이

.\TestPS.ps1 //IS 
+0

죄송에 선

$CmdArgsString = $CmdArgs -split "'n" 

을 변경 한 후 잘 작동합니다. 나는 나의 질문을 편집했다. –

+0

PS 코드와 요구 사항을 게시 할 수 있습니까? –

+0

@RanadipDutta 필자가 사용했던 PS 스크립트로 질문을 업데이트했습니다. 내 requirment는 내가 기계에 Windows 서비스를 설치하고 수동으로 서비스를 시작 해야이 스크립트를 실행할 때입니다. –

답변

0

같은 스크립트를 실행, PS에서 다음 cmdlet을 사용

$username = "Username" 
$password = "password" 
$secstr = New-Object -TypeName System.Security.SecureString 
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)} 
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr 

new-service -Name [INSERT SERVICE NAME] -DisplayName "[INSERT DISPLAY NAME]" -Description "[INSERT DESCRIPTION]" -BinaryPathName "[INSERT BINARY PATH]" -StartupType Manual -Credential $cred 

를 원하는 경우 원격으로 수행하려면 다음 함수를 사용하십시오.

function Install-Service(
    [string]$serviceName = $(throw "serviceName is required"), 
    [string]$targetServer = $(throw "targetServer is required"), 
    [string]$displayName = $(throw "displayName is required"), 
    [string]$physicalPath = $(throw "physicalPath is required"), 
    [string]$userName = $(throw "userName is required"), 
    [string]$password = "", 
    [string]$startMode = "Automatic", 
    [string]$description = "", 
    [bool]$interactWithDesktop = $false 
) 
{ 
    # can't use installutil; only for installing services locally 
    #[wmiclass]"Win32_Service" | Get-Member -memberType Method | format-list -property:*  
    #[wmiclass]"Win32_Service"::Create(...)   

    # todo: cleanup this section 
    $serviceType = 16   # OwnProcess 
    $serviceErrorControl = 1 # UserNotified 
    $loadOrderGroup = $null 
    $loadOrderGroupDepend = $null 
    $dependencies = $null 

    # description? 
    $params = ` 
     $serviceName, ` 
     $displayName, ` 
     $physicalPath, ` 
     $serviceType, ` 
     $serviceErrorControl, ` 
     $startMode, ` 
     $interactWithDesktop, ` 
     $userName, ` 
     $password, ` 
     $loadOrderGroup, ` 
     $loadOrderGroupDepend, ` 
     $dependencies ` 

    $scope = new-object System.Management.ManagementScope("\\$targetServer\root\cimv2", ` 
     (new-object System.Management.ConnectionOptions)) 
    "Connecting to $targetServer" 
    $scope.Connect() 
    $mgt = new-object System.Management.ManagementClass($scope, ` 
     (new-object System.Management.ManagementPath("Win32_Service")), ` 
     (new-object System.Management.ObjectGetOptions)) 

    $op = "service $serviceName ($physicalPath) on $targetServer"  
    "Installing $op" 
    $result = $mgt.InvokeMethod("Create", $params)  
    Test-ServiceResult -operation "Install $op" -result $result 
    "Installed $op" 

    "Setting $serviceName description to '$description'" 
    Set-Service -ComputerName $targetServer -Name $serviceName -Description $description 
    "Service install complete" 
} 
당신이 상승 모드 모두를 실행하고 있는지 확인하십시오 :

다음은 Guide to Install Windows Service Remotely

주입니다.

희망이 있습니다.

0

잘못된 서비스로 인해 문제가 발생했습니다. 그것은 prunsrv.exe의 문제가 있습니다.

이 스크립트는 불편을

$CmdArgsString  = $CmdArgs -split "`r`n" 
관련 문제