2014-03-26 57 views
0

我想運行一個腳本來安裝一些使用木偶的功能,但我得到一個奇怪的錯誤(正好是NullPointerException)。但是,如果我從機器中的用戶運行腳本,則所有內容都可以正常運行。我正在使用Apache Karaf 3.0.0和Puppet 2.7。與木偶運行Karaf客戶端的問題

我的劇本是很簡單:

#!/bin/bash 
#### 
#### A init script for Karaf 
#### 

# Repos 
for REPO in <%= repos.sort.join(' ') %> 
do 
    /opt/karaf/bin/client -a 8101 -h 127.0.0.1 -v feature:repo-add $REPO 
done 

# Features 
for FEATURE in <%= features.sort.join(' ') %> 
do 
    /opt/karaf/bin/client -a 8101 -h 127.0.0.1 -v feature:install $FEATURE 
done 

對於我只是用下面與Puppet運行它:

exec { 
'/opt/karaf/bin/init.sh' : 
    user  => 'root', 
    path  => ["/usr/bin", "/usr/sbin"], 
    logoutput => true, 
    require  => [Service['karaf'],File['/opt/karaf/bin/init.sh']]; 
} 

這是輸出在機器運行Puppet當我得到:

info: /Stage[main]/Karaf/File[/opt/karaf/bin/init.sh]: Filebucketed /opt/karaf/bin/init.sh to puppet with sum 7687821cc06d43754a4f44aa9b9a69ff 
notice: /Stage[main]/Karaf/File[/opt/karaf/bin/init.sh]/content: content changed '{md5}7687821cc06d43754a4f44aa9b9a69ff' to '{md5}6bb98d2e1079c66a7b9e16fff5ec1860' 
notice: /Stage[main]/Karaf/Exec[/opt/karaf/bin/init.sh]/returns: 30 [main] INFO org.apache.sshd.common.util.SecurityUtils - BouncyCastle not registered, using the default JCE provider 
notice: /Stage[main]/Karaf/Exec[/opt/karaf/bin/init.sh]/returns: 519 [pool-2-thread-1] INFO org.apache.sshd.client.session.ClientSessionImpl - Session created... 
notice: /Stage[main]/Karaf/Exec[/opt/karaf/bin/init.sh]/returns: java.lang.NullPointerException 
notice: /Stage[main]/Karaf/Exec[/opt/karaf/bin/init.sh]/returns: at org.apache.karaf.client.Main.main(Main.java:83) 
notice: /Stage[main]/Karaf/Exec[/opt/karaf/bin/init.sh]/returns: 20 [main] INFO org.apache.sshd.common.util.SecurityUtils - BouncyCastle not registered, using the default JCE provider 
notice: /Stage[main]/Karaf/Exec[/opt/karaf/bin/init.sh]/returns: 386 [pool-2-thread-1] INFO org.apache.sshd.client.session.ClientSessionImpl - Session created... 
notice: /Stage[main]/Karaf/Exec[/opt/karaf/bin/init.sh]/returns: java.lang.NullPointerException 
notice: /Stage[main]/Karaf/Exec[/opt/karaf/bin/init.sh]/returns: at org.apache.karaf.client.Main.main(Main.java:83) 
notice: /Stage[main]/Karaf/Exec[/opt/karaf/bin/init.sh]/returns: 27 [main] INFO org.apache.sshd.common.util.SecurityUtils - BouncyCastle not registered, using the default JCE provider 
notice: /Stage[main]/Karaf/Exec[/opt/karaf/bin/init.sh]/returns: 497 [pool-2-thread-1] INFO org.apache.sshd.client.session.ClientSessionImpl - Session created... 
notice: /Stage[main]/Karaf/Exec[/opt/karaf/bin/init.sh]/returns: java.lang.NullPointerException 

但是,如果我在我的用戶或根下運行它:

30 [main] INFO org.apache.sshd.common.util.SecurityUtils - BouncyCastle not registered, using the default JCE provider 
550 [pool-2-thread-1] INFO org.apache.sshd.client.session.ClientSessionImpl - Session created... 
561 [pool-2-thread-1] INFO org.apache.sshd.client.session.ClientSessionImpl - Server version string: SSH-2.0-SSHD-CORE-0.9.0 
Logging in as karaf 
564 [pool-2-thread-1] INFO org.apache.sshd.client.session.ClientSessionImpl - Received SSH_MSG_KEXINIT 
592 [pool-2-thread-1] INFO org.apache.sshd.client.kex.DHG1 - Send SSH_MSG_KEXDH_INIT 
602 [pool-2-thread-2] INFO org.apache.sshd.client.kex.DHG1 - Received SSH_MSG_KEXDH_REPLY 
619 [pool-2-thread-2] WARN org.apache.sshd.client.keyverifier.AcceptAllServerKeyVerifier - Server at /127.0.0.1:8101 presented unverified key: 
620 [pool-2-thread-2] INFO org.apache.sshd.client.session.ClientSessionImpl - Received SSH_MSG_NEWKEYS 
625 [pool-2-thread-2] INFO org.apache.sshd.client.session.ClientSessionImpl - Send SSH_MSG_SERVICE_REQUEST for ssh-userauth 
631 [main] INFO org.apache.sshd.client.auth.UserAuthAgent - Send SSH_MSG_USERAUTH_REQUEST for publickey 
643 [pool-2-thread-5] INFO org.apache.sshd.client.auth.UserAuthAgent - Received SSH_MSG_USERAUTH_SUCCESS 
675 [main] INFO org.apache.sshd.client.channel.ChannelExec - Send SSH_MSG_CHANNEL_OPEN on channel 101 
678 [pool-2-thread-2] INFO org.apache.sshd.client.channel.ChannelExec - Send SSH_MSG_CHANNEL_REQUEST exec 
Adding feature url mvn:io.hawt/hawtio-karaf/1.2.3/xml/features 
936 [pool-2-thread-5] INFO org.apache.sshd.client.channel.ChannelExec - Received SSH_MSG_CHANNEL_REQUEST on channel 101 
29 [main] INFO org.apache.sshd.common.util.SecurityUtils - BouncyCastle not registered, using the default JCE provider 
539 [pool-2-thread-1] INFO org.apache.sshd.client.session.ClientSessionImpl - Session created... 
Logging in as karaf 
552 [pool-2-thread-1] INFO org.apache.sshd.client.session.ClientSessionImpl - Server version string: SSH-2.0-SSHD-CORE-0.9.0 
554 [pool-2-thread-1] INFO org.apache.sshd.client.session.ClientSessionImpl - Received SSH_MSG_KEXINIT 
579 [pool-2-thread-1] INFO org.apache.sshd.client.kex.DHG1 - Send SSH_MSG_KEXDH_INIT 
592 [pool-2-thread-2] INFO org.apache.sshd.client.kex.DHG1 - Received SSH_MSG_KEXDH_REPLY 
609 [pool-2-thread-2] WARN org.apache.sshd.client.keyverifier.AcceptAllServerKeyVerifier - Server at /127.0.0.1:8101 presented unverified key: 
609 [pool-2-thread-2] INFO org.apache.sshd.client.session.ClientSessionImpl - Received SSH_MSG_NEWKEYS 
615 [pool-2-thread-2] INFO org.apache.sshd.client.session.ClientSessionImpl - Send SSH_MSG_SERVICE_REQUEST for ssh-userauth 
620 [main] INFO org.apache.sshd.client.auth.UserAuthAgent - Send SSH_MSG_USERAUTH_REQUEST for publickey 
631 [pool-2-thread-5] INFO org.apache.sshd.client.auth.UserAuthAgent - Received SSH_MSG_USERAUTH_SUCCESS 
668 [main] INFO org.apache.sshd.client.channel.ChannelExec - Send SSH_MSG_CHANNEL_OPEN on channel 101 
670 [pool-2-thread-2] INFO org.apache.sshd.client.channel.ChannelExec - Send SSH_MSG_CHANNEL_REQUEST exec 
Adding feature url mvn:org.apache.camel.karaf/apache-camel/2.13.0/xml/features 
985 [pool-2-thread-5] INFO org.apache.sshd.client.channel.ChannelExec - Received SSH_MSG_CHANNEL_REQUEST on channel 101 
27 [main] INFO org.apache.sshd.common.util.SecurityUtils - BouncyCastle not registered, using the default JCE provider 
515 [pool-2-thread-1] INFO org.apache.sshd.client.session.ClientSessionImpl - Session created... 
526 [pool-2-thread-1] INFO org.apache.sshd.client.session.ClientSessionImpl - Server version string: SSH-2.0-SSHD-CORE-0.9.0 
Logging in as karaf 
528 [pool-2-thread-1] INFO org.apache.sshd.client.session.ClientSessionImpl - Received SSH_MSG_KEXINIT 
553 [pool-2-thread-1] INFO org.apache.sshd.client.kex.DHG1 - Send SSH_MSG_KEXDH_INIT 
562 [pool-2-thread-2] INFO org.apache.sshd.client.kex.DHG1 - Received SSH_MSG_KEXDH_REPLY 
578 [pool-2-thread-2] WARN org.apache.sshd.client.keyverifier.AcceptAllServerKeyVerifier - Server at /127.0.0.1:8101 presented unverified key: 
579 [pool-2-thread-2] INFO org.apache.sshd.client.session.ClientSessionImpl - Received SSH_MSG_NEWKEYS 
584 [pool-2-thread-2] INFO org.apache.sshd.client.session.ClientSessionImpl - Send SSH_MSG_SERVICE_REQUEST for ssh-userauth 
590 [main] INFO org.apache.sshd.client.auth.UserAuthAgent - Send SSH_MSG_USERAUTH_REQUEST for publickey 
602 [pool-2-thread-5] INFO org.apache.sshd.client.auth.UserAuthAgent - Received SSH_MSG_USERAUTH_SUCCESS 
630 [main] INFO org.apache.sshd.client.channel.ChannelExec - Send SSH_MSG_CHANNEL_OPEN on channel 101 
632 [pool-2-thread-2] INFO org.apache.sshd.client.channel.ChannelExec - Send SSH_MSG_CHANNEL_REQUEST exec 
666 [pool-2-thread-4] INFO org.apache.sshd.client.channel.ChannelExec - Received SSH_MSG_CHANNEL_REQUEST on channel 101 

是不是Puppet做了一些我不知道的事情?卡拉夫3.0.0的客戶端有bug嗎?感謝和抱歉的長篇文章!

+0

看來,調用'System.console(..)'當木偶運行返回null。你知道這個解決方法嗎? – hveiga

+0

的確如此,我發現了JIRA票:https://issues.apache.org/jira/browse/KARAF-2663 – hveiga

回答

2

我對傀儡瞭解不多。傀儡試圖抓住卡拉夫客戶端在控制檯吐出的東西。如果是這樣,那麼空指針異常很有可能。我還沒有想出一個方法來捕捉karaf客戶端的輸出。 Here's something I posted on SO related to this

+0

感謝您的評論。我遇到了同樣的問題,但我決定只使用純SSH而不是客戶端。我相信在客戶端(對於我的場景)中存在一個錯誤,因爲它似乎在運行時Puppet沒有附加控制檯,因此'System.console(..)'返回'null',並且在嘗試使用它時,它拋出'NullPointerException' – hveiga

0

正是在Karaf 3.0.0一個錯誤,它已被固定在Karaf 3.0.1

+3

如果這確實是解決方案,請提供更多信息,並可能提供某種鏈接或引用。 – ebarr