postgresql 如何使用 CLI 向 Wildfly 添加模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32332782/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add module to Wildfly using CLI
提问by Magick
I'm trying to create a Wildfly docker image with a postgres datasource.
我正在尝试使用 postgres 数据源创建 Wildfly docker 图像。
When I build the dockerfile it always fails with Permission Denied when I try to install the postgres module.
当我构建 dockerfile 时,当我尝试安装 postgres 模块时,它总是以 Permission Denied 失败。
My dockerfile looks look this:
我的 dockerfile 看起来像这样:
FROM wildflyext/wildfly-camel
RUN /opt/jboss/wildfly/bin/add-user.sh admin admin --silent
ADD postgresql-9.4-1201.jdbc41.jar /tmp/
ADD config.sh /tmp/
ADD batch.cli /tmp/
RUN /tmp/config.sh
Which calls the following:
其中调用以下内容:
#!/bin/bash
JBOSS_HOME=/opt/jboss/wildfly
JBOSS_CLI=$JBOSS_HOME/bin/jboss-cli.sh
JBOSS_MODE=${1:-"standalone"}
JBOSS_CONFIG=${2:-"$JBOSS_MODE.xml"}
function wait_for_wildfly() {
until `$JBOSS_CLI -c "ls /deployment" &> /dev/null`; do
sleep 10
done
}
echo "==> Starting WildFly..."
$JBOSS_HOME/bin/$JBOSS_MODE.sh -c $JBOSS_CONFIG > /dev/null &
echo "==> Waiting..."
wait_for_wildfly
echo "==> Executing..."
$JBOSS_CLI -c --file=`dirname "batch
module add --name=org.postgresql --resources=/tmp/postgresql-9.4-1201.jdbc41.jar --dependencies=javax.api,javax.transaction.api
/subsystem=datasources/jdbc-driver=postgresql:add(driver-name=postgresql,driver-module-name=org.postgresql,driver-xa-datasource-class-name=org.postgresql.xa.PGXADataSource)
run-batch
"`/batch.cli --connect
echo "==> Shutting down WildFly..."
if [ "$JBOSS_MODE" = "standalone" ]; then
$JBOSS_CLI -c ":shutdown"
else
$JBOSS_CLI -c "/host=*:shutdown"
fi
And
和
connect
module add --name=sqlserver.jdbc --resources=@INSTALL_FOLDER@/libext/jtds-1.3.1.jar --dependencies=javax.api,javax.transaction.api
/subsystem=datasources/jdbc-driver=sqlserver:add(driver-module-name=sqlserver.jdbc,driver-name=sqlserver,driver-class-name=@JDBC_DRIVER@)
/subsystem=datasources/data-source=@DATASOURCENAME@:add(jndi-name=java:jboss/@JNDI_NAME@,enabled="true",use-java-context="true",driver-name=sqlserver,connection-url="@JDBC_URL@",user-name=@JDBC_USER@,password=@JDBC_PASSWORD@,validate-on-match=true,background-validation=true)
The output when building is:
构建时的输出是:
==> Starting WildFly... ==> Waiting... ==> Executing... Failed to locate the file on the filesystem copying /tmp/postgresql-9.4-1201.jdbc41.jar to /opt/jboss/wildfly/modules/org/postgresql/main/postgresql-9.4-1201.jdbc41.jar: /tmp/postgresql-9.4-1201.jdbc41.jar (Permission denied)
==> 正在启动 WildFly... ==> 正在等待... ==> 正在执行... 无法在将 /tmp/postgresql-9.4-1201.jdbc41.jar 复制到 /opt/jboss/wildfly 的文件系统上找到该文件/modules/org/postgresql/main/postgresql-9.4-1201.jdbc41.jar:/tmp/postgresql-9.4-1201.jdbc41.jar(权限被拒绝)
What permissions are required, and where do I set the permission(s)?
需要什么权限,在哪里设置权限?
Thanks
谢谢
回答by kwart
It seems the JAR file is not readable by the jboss
user (the user comming from parent image). The postgresql-9.4-1201.jdbc41.jar
is added under the root user - find details in this GitHub discussion.
jboss
用户(来自父映像的用户)似乎无法读取 JAR 文件。该postgresql-9.4-1201.jdbc41.jar
是root用户下添加-发现细节此GitHub上的讨论。
You could
你可以
- either add permissions to JAR filebefore adding it to the image
- or add permissions to JAR file in the image after the adding
- or change ownership of the file in the image
- 在将 JAR 文件添加到图像之前添加权限
- 或者在添加后为镜像中的JAR文件添加权限
- 或更改图像中文件的所有权
The simplest solution could be the first one. The other 2 solutions need also switching user to root (USER root
in dockerfile) and then back to jboss.
最简单的解决方案可能是第一个。其他 2 个解决方案还需要将用户切换到 root(USER root
在 dockerfile 中),然后再切换回 jboss。
回答by Alex
Here a advice : make a cli file like this :
这里有一个建议:制作一个像这样的 cli 文件:
##代码##replace @VAR@ by our own value... and It should work! Be caution than JBOSS/Wildfly 10 think relatively for jar --resources by default but wildfly 8 think absolute path this could make you weird ! ;-)
用我们自己的值替换@VAR@...它应该可以工作!比 JBOSS/Wildfly 10 谨慎考虑 jar --resources 默认情况下,但 Wildfly 8 认为绝对路径这可能会让你觉得奇怪!;-)
cheers!
干杯!