Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query regarding Zookeeper Windows API start/stop, using Zk as a windows service(using prunsrv)

I am using zookeeper in my product(3.3.3). While working with zookeeper on Windows, I am creating a service(using prunsrv) , I have few queries and issues. Listed them all,

Issues: 1) zkServer.cmd didn’t start on Win server 2008 machine & Win 7 Enterprise(64 bit both), had to replace the following line,

java "-Dzookeeper.log.dir=%ZOO_LOG_DIR%" "-Dzookeeper.root.logger=%ZOO_LOG4J_PROP%" -cp "%CLASSPATH%" %ZOOMAIN% "%ZOOCFG%" %*

to

java "-Dzookeeper.log.dir=%ZOO_LOG_DIR%" "-Dzookeeper.root.logger=%ZOO_LOG4J_PROP%" -cp "%CLASSPATH%" %ZOOMAIN% "%ZOOCFG%"
          And it worked, could it be fixed in some other way?

2) In the zoo.cnf I specified the dataDir, still it creates some other directory (bin/zookeeper-3.4.5zookeeper-3.4.5data/ version-2/snapshot) and stores the snapshots there.

Queries: 1) There is no start/stop with zkServer.cmd as it is in zkServer.sh, so basically it is started with zkServer.cmd but to stop I do a Ctrl+C/Z So if I start the process, it is a foreground process and gets killed when I do a ctrl+C

2) I have to create a zookeeper service, and I am using prunsrv to do that. I figured out the following 2 ways to do so.

a)   

prunsrv //IS//Zookeeper --DisplayName=" ZOOKEEPER Service" --Description=" ZOOKEEPER Service" --Startup=auto --StartMode=exe --StartPath=%ZOOKEEPER_HOME% --StartImage=%ZOOKEEPER_HOME%\bin\zkServer.cmd --StopTimeout=5 --LogPath=%LOGS_DIR% --LogPrefix=zookeeper --LogLevel=Info --PidFile=zookeeper.pid --StdOutput=auto --StdError=auto


b)  

cd %ZOOKEEPER_HOME%\bin\
                call "%~dp0zkEnv.cmd"
                set ZOOMAIN=org.apache.zookeeper.server.quorum.QuorumPeerMain
                prunsrv //IS//Zookeeper --DisplayName=" ZOOKEEPER Service" --Description=" ZOOKEEPER Service" --Jvm="%JVM_DLL%" --JvmOptions=!JAVA_OPTS!  --Environment=zookeeper.log.dir=%ZOO_LOG_DIR%;zookeeper.root.logger=%ZOO_LOG4J_PROP%; --Startup=auto --LibraryPath=%LIB_DIR% --StartMode=jvm --Classpath=%CLASSPATH% %ZOOMAIN% %ZOOCFG% --StartClass=org.apache.zookeeper.server.quorum.QuorumPeerMain --StartMethod=start --StopMode=jvm --StopClass=org.apache.zookeeper.server.quorum.QuorumPeerMain --StopMethod=stop --StopTimeout=10 --LogPath=%LOGS_DIR% --LogPrefix=zookeeper --LogLevel=Info --PidFile=zookeeper.pid --StdOutput=auto --StdError=auto

basically in the second approach I am myself doing all tasks done by the zkServer.cmd

=>> My Query is in the second step(2b), that to stop the service there should be a stop method exposed, so that when I stop the service it is called. So right now if I create a service and start it, ZK runs fine, but stopping it takes indefinitely, so I have to go and kill the process. Is there some stop() for the same, I see a shutdown() but there is no description for it

I went through the class org.apache.zookeeper.server.quorum.QuorumPeerMain, here the main() is the start method( if my understanding is correct), and there should be some method to shutdown the process.

Just got the following link

https://issues.apache.org/jira/browse/ZOOKEEPER-1122, exposes a start/stop, but the stop has some issues

it throws the following error:

E:\zookeeper-3.4.5\zookeeper-3.4.5\bin>zkServer.cmd stop
"JMX enabled by default"
"Using config: E:\zookeeper-3.4.5\zookeeper-3.4.5\bin\..\conf\zoo.cfg"
 "Stopping zookeeper ... "
ERROR: The process with PID 452 (child process of PID 4) could not be terminated.
Reason: This is critical system process. Taskkill cannot end this process.
ERROR: The process with PID 4 (child process of PID 0) could not be terminated.
Reason: Access is denied.
ERROR: The process with PID 0 (child process of PID 0) could not be terminated.
Reason: This is critical system process. Taskkill cannot end this process.
STOPED

I am running this stop command on a Administrator console.

E:\zookeeper-3.4.5\zookeeper-3.4.5\bin>tasklist | findstr "java" java.exe 10324 Console 1 36,036 K.

Any help would be highly appreciated

like image 278
nandini Avatar asked Oct 01 '22 08:10

nandini


People also ask

How do I stop ZooKeeper on Windows?

Complete the following steps: To find the process ID for ZooKeeper, type ps -eo pid,command | grep "QuorumPeer" | grep -v grep | awk '{print $1}' at the command line. To kill the ZooKeeper process, type kill -9 <type the ZooKeeper PID retrieved from the previous step>.

Which of the four letter word commands will show you the status of a ZooKeeper server?

The following are the four-letter words supported by ZooKeeper services at the time of writing this book: conf : This print details about server configuration parameters such as clientPort , dataDir , tickTime, and so on.


1 Answers

So what you want to do is run Zookeeper as a Windows service. I had the same requirement, here is the solution I have chosen:

  1. Prereqs: Zookeeper & prunsrv
  2. Set ZOOKEEPER_SERVICE environment variable to the name of the windows service to create, and ZOOKEEPER_HOME to the path to the zookeeper home folder. Then,

    prunsrv.exe "//IS//%ZOOKEEPER_SERVICE%" ^
            --DisplayName="Zookeeper (%ZOOKEEPER_SERVICE%)" ^
            --Description="Zookeeper (%ZOOKEEPER_SERVICE%)" ^
            --Startup=auto --StartMode=exe ^
            --StartPath=%ZOOKEEPER_HOME% ^
            --StartImage=%ZOOKEEPER_HOME%\bin\zkServer.cmd ^
            --StopPath=%ZOOKEEPER_HOME%\ ^
            --StopImage=%ZOOKEEPER_HOME%\bin\zkServerStop.cmd ^
            --StopMode=exe --StopTimeout=5 ^
            --LogPath=%ZOOKEEPER_HOME% --LogPrefix=zookeeper-wrapper ^
            --PidFile=zookeeper.pid --LogLevel=Info --StdOutput=auto --StdError=auto
    
  3. Add a zkServerStop.cmd file in zookeeper bin folder with the following content:

    @echo off
    setlocal
    TASKLIST /svc | findstr /c:"%ZOOKEEPER_SERVICE%" > %ZOOKEEPER_HOME%\zookeeper_svc.pid
    FOR /F "tokens=2 delims= " %%G IN (%ZOOKEEPER_HOME%\zookeeper_svc.pid) DO (
        @set zkPID=%%G
    )
    taskkill /PID %zkPID% /T /F
    del %ZOOKEEPER_HOME%/zookeeper_svc.pid
    endlocal
    

    (Of course it needs the two environment variables ZOOKEEPER_HOME & ZOOKEEPER_SERVICE to be set)

Hope it helps,
Guillaume.

like image 149
Guillaume Avatar answered Oct 20 '22 17:10

Guillaume