Linux添加系统服务

来源:互联网 发布:家庭网络需要交换机吗 编辑:程序博客网 时间:2024/04/30 02:11

实践资料:

添加Linux的服务需要了解linux的脚本,详细文见:http://blog.csdn.net/luopeiyuan1990/article/details/8193359
使用ubuntu 添加了系统服务。
对文章的注解:
nohup:指后台服务
touch:创建目录
&1这些变量见上面的博文介绍
像是ubuntu这样的发行版linux才有chkconfig,而openwrt这样的linux没有,它有自己的启动添加方法,脚本有具体的写方法,而后创建连接到rc.d目录。

参考文章资料:

要在Linux添加服务,随系统启动自动运行:
以Redhat 5为例

1.把以下内容添加的一个文件(xxx)中,然后复制到/etc/init.d/目录下
 #!/bin/bash
#
# Startup script for the pmagent
#
# chkconfig: 345 99 02
# description: Run the xxx 
INITLOG_ARGS=""
prog="xxx"
progname="xxx"
RETVAL=0
# Edit the following to indicate the 'bin' directory for your installation
MDIR=/opt/xxx
if [ ! -d "$MDIR" ]
then
echo "Invalid directory $MDIR"
exit 1
fi
start()
{
mv -f /var/log/xxx.log /var/log/xxx1.log
echo "Starting $progname"
cd $MDIR
nohup sh startxxx.sh >/var/log/xxx.log 2>&1 &
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/Xxx 
}
stop()
{
echo "Stopping $progname"
cd $MDIR
sh shutdownxxx.sh >>/var/log/xxx.log 2>&1
}
case "$1" in
start)
start
;;
stop)
stop
;;
*)
echo "Usage: $prog {start|stop}"
exit 1
;;
esac
exit $RETVAL 

3. # chmod 755 /etc/init.d/xxx

4. 使用下面的命令添加脚本到启动进程 # chkconfig --add xxx
(debina命令:update-rc.d xxx defaults)

原创粉丝点击