编辑脚本

本例以添加svnserve为例

#!/bin/sh#echo $1START='svnserve -d -T -r /home/rocky/programs/svnrepo/'PID="`ps aux | grep svnserve -d -T -r /home/rocky/programs/svnrepo/ | grep -v grep|awk '{print $2}'`"case $1 in        'start')                id=$PID                if [ "$id" = "" ];then                        $START                fi                echo 'START SVNSERVE [OK]'                ;;        'stop')                id=$PID                if [ "$id" != "" ];then                        kill $id                fi                echo 'STOP  SVNSERVE [OK]'                ;;        'restart')                id=$PID                if [ "$id" != "" ];then                        kill $id                fi                echo 'STOP  SVNSERVE [OK]'                $START                echo 'START SVNSERVE [OK]'                ;;        '')                $START                ;;esac

执行update-rc.d命令

把启动脚本保存为svnserve,存放在/etc/init.d/目录下

cd /etc/init.d/update-rc.d svnserve defaults 20输出如下:update-rc.d: warning: /etc/init.d/svnserve missing LSB informationupdate-rc.d: see <http://wiki.debian.org/LSBInit s> Adding system startup for /etc/init.d/svnserve ...   /etc/rc0.d/K20svnserve -> ../init.d/svnserve   /etc/rc1.d/K20svnserve -> ../init.d/svnserve   /etc/rc6.d/K20svnserve -> ../init.d/svnserve   /etc/rc2.d/S20svnserve -> ../init.d/svnserve   /etc/rc3.d/S20svnserve -> ../init.d/svnserve   /etc/rc4.d/S20svnserve -> ../init.d/svnserve   /etc/rc5.d/S20svnserve -> ../init.d/svnserve

20代表启动顺序,这个数值越大,则越后启动
至此,下次重启电脑就会自动执行该脚本命令

立即启动服务

service svnserve start

其他命令

service svnserve stop
service svnserve restart

收藏 打印