Review Board 1.7.22


Run Flume Agent as Windows Service

Review Request #12822 - Created July 22, 2013 and updated

Sergey Sirotkin
FLUME-1336
Reviewers
Flume
flume-git
This patch adds files necessary to run Flume Agent as Windows Service.

I added two folders under \bin: win32 and win64. Both of them contain corresponding version of prunsrv.exe and two PowerShell scripts for installing/uninstalling FlumeAgent service: InstallService.ps1 and UninstallService.ps1.

In order to install the service, open PowerShell promptand type (I assume you have 64-bit operating system and 64-bit version of Java). You might need to enable script execution by running
Set-ExecutionPolicy RemoteSigned
then type:
cd \apache-flume\bin\win64
.\InstallService.ps1

After that service will be installed, and you can start it:
net start FlumeAgent

In order to uninstall service, do the following:
cd \apache-flume\bin\win64
.\UninstallService.ps1

Log files (including one created by prunsrv) are stored in logs.

x86 and x64 Versions
There are two versions of prunsrv for different architectures: x86 (32-bit) and x64 (64-bit). You need to choose which one to use based on the version of Java you have installed. I configured prunsrv to use such called JVM-mode. In that mode prunesrv.exe loads jvm.dll from JRE and then runs that VM. If you have 32-bit version of Java, 64-bit prunsrv will not be able to load 32-bit version of jvm.dll and service will not start.

 
bin/win32/InstallService.ps1
New File

    
   
1
# Licensed to the Apache Software Foundation (ASF) under one

    
   
2
# or more contributor license agreements.  See the NOTICE file

    
   
3
# distributed with this work for additional information

    
   
4
# regarding copyright ownership.  The ASF licenses this file

    
   
5
# to you under the Apache License, Version 2.0 (the

    
   
6
# "License"); you may not use this file except in compliance

    
   
7
# with the License.  You may obtain a copy of the License at

    
   
8
#

    
   
9
# http://www.apache.org/licenses/LICENSE-2.0

    
   
10
#

    
   
11
# Unless required by applicable law or agreed to in writing,

    
   
12
# software distributed under the License is distributed on an

    
   
13
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

    
   
14
# KIND, either express or implied.  See the License for the

    
   
15
# specific language governing permissions and limitations

    
   
16
# under the License.

    
   
17

   

    
   
18
 

    
   
19
$serviceName = "FlumeAgent"

    
   
20
$agentName = "agent1"

    
   
21

   

    
   
22
if ($env:JAVA_HOME -eq "") 

    
   
23
{

    
   
24
    Write-Error "JAVA_HOME is not set."

    
   
25
    Exit 1

    
   
26
}

    
   
27

   

    
   
28
Write-Host "JAVA_HOME is set to $env:JAVA_HOME"

    
   
29

   

    
   
30
# get Flume folder

    
   
31

   

    
   
32
$scriptRootPath = Split-Path -Parent $MyInvocation.MyCommand.Path

    
   
33
$flumePath = Split-Path -Parent (Split-Path -Parent $scriptRootPath)

    
   
34

   

    
   
35
Write-Host "Flume directory is $flumePath"

    
   
36

   

    
   
37
# Install service using prunsrv

    
   
38

   

    
   
39
& $scriptRootPath\prunsrv.exe  //IS//$serviceName `

    
   
40
            --DisplayName="Flume Agent" `

    
   
41
            --Description="Collects, aggregates and moves log data." `

    
   
42
            --LogPath=$flumePath\logs `

    
   
43
            --LogPrefix=prunsrv `

    
   
44
            --Install=$scriptRootPath\prunsrv.exe `

    
   
45
            --Jvm=auto `

    
   
46
            --StartMode=jvm `

    
   
47
            --StopMode=jvm `

    
   
48
            --Classpath=$flumePath\lib\* `

    
   
49
            ++JvmOptions=-Dlog4j.configuration=$flumePath\conf\log4j.properties `

    
   
50
            --StartClass=org.apache.flume.node.Application `

    
   
51
            --StopClass=org.apache.flume.node.Application `

    
   
52
            --StopMethod=stop `

    
   
53
            ++StartParams=-n`;$agentName`;-f`;$flumePath\conf\flume.conf
bin/win32/UninstallService.ps1
New File
 
bin/win32/prunsrv.exe
New File
 
bin/win64/InstallService.ps1
New File
 
bin/win64/UninstallService.ps1
New File
 
bin/win64/prunsrv.exe
New File
 
flume-ng-node/src/main/java/org/apache/flume/node/Application.java
Revision 5250139 New Change
 
  1. bin/win32/InstallService.ps1: Loading...
  2. bin/win32/UninstallService.ps1: Loading...
  3. bin/win32/prunsrv.exe: Loading...
  4. bin/win64/InstallService.ps1: Loading...
  5. bin/win64/UninstallService.ps1: Loading...
  6. bin/win64/prunsrv.exe: Loading...
  7. flume-ng-node/src/main/java/org/apache/flume/node/Application.java: Loading...