您的位置:首页 > 其它

Ubuntu笔记--添加启动脚本

2015-04-02 15:57 148 查看

编辑脚本

本例以添加svnserve为例

#!/bin/sh

#echo $1

START='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 information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: