大网数据广告活动
服务器运维问答

Can I use ansible to startup jboss service in domain mode?

· 52CE 我爱测

I used sh /usr/local/jboss/bin/domain.sh manually, and jboss works fine. When I use ansible to start jboss automatically, jboss log always shows " Container is down ". File /root/startup_jboss.sh : #!/bin/bash /bin/sh /usr/local/…

问题原文

原帖链接 · user2612797 · CC BY-SA 3.0

I used sh /usr/local/jboss/bin/domain.sh manually, and jboss works fine.

When I use ansible to start jboss automatically, jboss log always shows "Container is down".

File /root/startup_jboss.sh :

#!/bin/bash
/bin/sh /usr/local/jboss/bin/domain.sh &

My startup.yml:

---
- name: Tranfser and Execute a script
  hosts: AuditReport

  tasks:
     - name: Tranfser the scipt
       command: chdir=/root /bin/sh startup_jboss.sh

I don't know why?

Could anyone help me?

Thanks.

Regards, Cloud

已采纳解答

原帖链接 · sebbrochet · CC BY-SA 3.0

The error you encounter is related to the fact that the context of the execution of the domain.shscript is different when you're logged in and when it is executed remotely by Ansible. See this SO question for more details.

You need to complete the /root/startup_jboss.shscript with the missing environment variables in order to work correctly. You can test it in the same conditions than ansible with a remote SSH command:

ssh root@<your node> /root/startup_jboss.sh

You may use Ansible to execute a shell script on a remote server but I don't think it's the right solution in your use-case.

Ansible is a Configuration Management tool that is designed to describe desired states for your resources (files, process, rights, ...) and ensure idempotency (only the changes that are required are done, you can run your script multiple times and you always get the same state). In your use-case, you'd like to ensure JBoss is running in domain mode on your remote server. The way I'd tackle it is to encapsulate the domain.sh script inside a init script to have it running as a service and eventually configure this service to run at server startup. I don't know what is your linux distro but you may have a look here for an example of an init.d script for Debian.

In your startup.yml playbook you'd first copy the init.d script and then ensure your service is running (Ansible provides a native module to manage services).

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-05-06)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。