免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 848 | 回复: 0
打印 上一主题 下一主题

添加linux系统服务 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-01-30 21:32 |只看该作者 |倒序浏览


在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服务是否正常启动

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/12056/showart_1809054.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP