use*_*745 7 linux amazon-ec2 ec2-ami
我正在使用Amazon Linux AMI并对其进行一些自定义修改(添加了axis2server等)并将其保存为新的AMI.现在我想要做的是当AMI启动时,启动axis2server(ie.saxis2server应该在实例启动时自动启动).为此,我使用了如下的init脚本并运行以下命令:
chkconfig --add axisservice
Run Code Online (Sandbox Code Playgroud)
但是当我从我的图像中启动一个新实例时,axis2server还没有开始.
我只需要在启动时执行脚本/home/ec2-user/axis2-1.6.1/bin/axis2server.sh.我在这里错过了什么吗?
#! /bin/sh
# Basic support for IRIX style chkconfig
###
# chkconfig: 235 98 55
# description: Manages the services you are controlling with the chkconfig command
###
case "$1" in
start)
echo -n "Starting axisservice"
touch ~/temp.txt
cd /home/ec2-user/axis2-1.6.1/bin
./axis2server.sh &
echo "."
;;
stop)
echo -n "Stopping axisservice"
echo "."
;;
*)
echo "Usage: /sbin/service axisservice {start|stop}"
exit 1
esac
exit 0
Run Code Online (Sandbox Code Playgroud)
我还浏览了https://help.ubuntu.com/community/CloudInit,它提供了一种名为User-Data Scripts的机制,用户可以在启动脚本时执行脚本.
$ euca-run-instances --key mykey --user-data-file myscript.sh ami-axxxx
Run Code Online (Sandbox Code Playgroud)
这是一个命令行选项,我想要的是当我通过UI启动实例时,应该启动脚本.因此,我认为上面的选项不能用于我的情况.如果我错了,请纠正我.
谢谢,H.
我敢打赌环境没有设置(正确设置)。这意味着我猜测您的 shell 脚本尝试启动另一个程序,但找不到它。
所以首先,我会调整start脚本的部分(当前):
echo -n "Starting axisservice"
touch ~/temp.txt
cd /home/ec2-user/axis2-1.6.1/bin
./axis2server.sh &
echo "."
Run Code Online (Sandbox Code Playgroud)
编辑:
echo -n "Starting axisservice"
touch ~/temp.txt
cd /home/ec2-user/axis2-1.6.1/bin
./axis2server.sh
RETVAL=$?
[ $RETVAL -eq 0 ] && echo Success
[ $RETVAL -ne 0 ] && echo Failure
echo "."
Run Code Online (Sandbox Code Playgroud)
那么我做了什么?
&,因此脚本等待您的 shell 脚本 (axis2server.sh) 完成$?检查shell 脚本的返回状态 ( )进一步调试:
添加set -x到您的脚本以启用跟踪并记录stderr和stdout。
问题:
stop(在您的服务脚本中)没有执行任何操作?touch ~/temp.txt那应该创造吗/root/temp.txt?(我猜root 运行这个脚本。)axis2server.sh并粘贴stderr吗stdout?| 归档时间: |
|
| 查看次数: |
10833 次 |
| 最近记录: |