我正在尝试运行一个脚本来使用puppet安装一些功能但我得到一个奇怪的错误(恰好是NullPointerException
)。但是,如果我从机器中的用户运行脚本,一切都正常运行。我使用的是Apache Karaf
3.0.0和Puppet
2.7。
我的脚本非常简单:
#!/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
但是,如果我在我的用户或root下运行它:
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
做了我失踪的事吗?客户端是否存在Karaf 3.0.0的错误?谢谢,抱歉这篇长篇文章!
答案 0 :(得分:2)
我对傀儡知之甚少。是木偶试图抓住karaf客户端在控制台中吐出的东西。如果是这样,则很可能出现空指针异常。我还没有找到一种方法来捕获karaf客户端的输出。 Here's something I posted on SO related to this
答案 1 :(得分:2)
似乎这在3.0.1中已得到修复。有关详细信息,请参阅以下Jira报告:
答案 2 :(得分:0)
这是Karaf 3.0.0中的一个错误,已经在Karaf 3.0.1中修复了