欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入
Linux下将普通软件启动方式做成service方式
以这次安装的openmeeting为例:
目录结构:/root/openmeeting_dirnary/admin.bat
admin.sh
…
red5.sh
red5-shutdown.bat
red5-shutdown.sh
…
如果要启动它我们普通的方式都是进入这个/root/openmeeting_dirnary/这个目录,
执行:./red5.sh & (当然要有执行权限)
现在我们要做的工作就是:
将它的启动、关闭等方式做成service ….. stop|start|restart|status|restart的方式
cd /etc/init.d/
touch openmeetingd (我们自己起的名字,仿照一般的服务,比如httpd….)
贴出该文件的代码,然后再细细解释:
#start Red5 demon
start(){ #这一步没什么好说的,就是进入到目录,改权限,启动…
echo “starting red5 …”
cd /root/openmeeting_binary/
chmod 755 red5.sh
./red5.sh &
echo “Red5 started successful …”
}
#stop red5 demon
stop(){ # 在下面详细讲解
pid=`ps -ef|grep “java”|grep -v “grep”|awk ‘{print $2}’`
if [ “$pid” == “” ];then
echo “No red5 pid alive …”
else
echo “now , kill pid $pid …”
kill $pid
echo “Red5 stopped successful …”
fi
}
#show the status of red5
status(){ #通过判断进程是否启动着,即pid是否存在为依据来判断状态
pid=`ps -ef | grep “java” | grep -v “grep” | awk ‘{print $2}’`
if [ “$pid” == “” ];then
echo “red5 is stopped …”
else
echo “red5 is running …”
fi
}
#restart red5 demo
restart(){ # 调用前面的函数,很简单吧…
stop
start
}
#execute by input command # 根据输入的命令来判断应该执行什么
case “$1” in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
*)
echo $”Usage: $0 {start|stop|status|restart}”
exit 1
[1][2]
孤独是一种无奈的选择,孤独是因为没有找到合适的同行者,