Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1322770
  • 博文数量: 334
  • 博客积分: 10302
  • 博客等级: 上将
  • 技术积分: 2986
  • 用 户 组: 普通用户
  • 注册时间: 2006-01-12 10:17
文章分类

全部博文(334)

文章存档

2013年(1)

2012年(9)

2011年(4)

2010年(10)

2009年(24)

2008年(64)

2007年(72)

2006年(150)

我的朋友

分类: LINUX

2009-01-30 21:32:41

 

在linux系统中,如果计划将一些服务添加到系统服务列表中,类似sshd,vsftpd,httpd服务一样,能够随机启动,并且能够通过service httpd start/stop这样的命令启动或者关闭,那么我们可以如此来解决:
在此我们拿tomcat来作例:
<一>.
编写自动启动tomcat脚本,下面是一个例子,我们将脚本保存为tomcat

备注:tomcat,jdk,环境变量的设置在此就不赘述,在此我们将tomcat程序文件安装在/opt目录下,tomcat自动启动脚本放置在/opt/script目录下,
[root@shell init.d]#vi tomcat
#!/bin/bash
#
# tomcat
This script is used for start or stop

#
the tomcat Daemon

# chkconfig: 345 88 14

# description: Tomcat Daemon
# 上面的两行必须有,否则不支持chkconfig
# Author: Nick
# Writen: 2008.10.23
#
#
. /etc/profile
start()
{
echo "#############################starting the tomcat#################################################"
/opt/tomcat/bin/startup.sh;
exit 0;
}

stop()
{
echo "#############################stopping the tomcat#################################################";
tomcatpro=`ps -ef |grep tomcat |grep -v grep | awk '{print $2}'`;
kill -9 $tomcatpro;
exit 0;
}

case "$1" in
start)
start
;;
stop)
stop
;;
esac
<二>.
将tomcat脚本复制到/etc/init.d目录下,然后运行chkconfig命令添加系统服务

cp /opt/script/tomcat /etc/init.d/tomcat
chkconfig --add tomcat
<三>.
让tomcat服务随机启动,在此运行chkconfig命令

chkconfig – --level 3 tomcat on
<四>.
重启linux系统,验证tomcat服务是否正常启动
阅读(1042) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~