SVN+Nginx自动部署脚本

功能:创建新仓库,修改仓库配置(使用全局配置),配置钩子程序,检索,配置nginx虚拟主机


脚本内容:

#!/bin/bash
read -p "仓库名称:" domain
#domain=$1

# SVN仓库路径
svndir=/svn

# SVN配置文件路径
confdir=/svn/conf

# web目录
wwwroot=/data/htdocs

#nginx虚拟主机目录
vhost=/usr/local/nginx/conf/vhost




#创建SVN仓库
if [ -d $svndir/$domain ]
    then
           echo "仓库已存在"
           exit
    else
            /usr/bin/svnadmin create $svndir/$domain
            echo "仓库创建完成"
fi

#拷贝配置文件
/bin/cp $confdir/svnserve.conf $svndir/$domain/conf/svnserve.conf
if [[ $? -eq 0 ]]
    then
        echo "拷贝配置文件完成"
    else
        echo "拷贝配置文件失败"
        exit
fi

#配置钩子,checkout
if [ -d $wwwroot/$domain ]
    then
        echo "网站目录已存在,钩子配置停止"
        exit
    else
        /bin/cp $confdir/post-commit $svndir/$domain/hooks
        /bin/sed -i "s/domain/$domain/g" $svndir/$domain/hooks/post-commit
        /bin/chmod +x /$svndir/$domain/hooks/post-commit
        echo "钩子配置完成"
fi

/usr/bin/svn co --username=sync --password sync svn://localhost/$domain $wwwroot/$domain
if [[ $? -eq 0 ]]
then
    echo "SVN检索完成"
else
    echo "SVN检索失败"
fi


#配置nginx虚拟主机

if [ -f $vhost/$domain ]
    then
        echo "虚拟主机配置文件已存在,nginx配置虚拟主机停止"
        exit
    else
        /bin/cp $confdir/vhost.conf $vhost/$domain.conf
        sed -i "s/domain/$domain/g" $vhost/$domain.conf
fi

if [[ $? -eq 0 ]]
then
    echo "vhost配置文件已生成"
else
    echo "vhost配置文件生成失败"
fi


#nginx检测配置文件
/usr/local/nginx/sbin/nginx -t
if [[ $? -eq 0 ]]
then
    /etc/init.d/nginx reload
    echo "重启nginx完成"
    echo "项目访问URL: $domain"
else
    echo "配置文件出现出错,请检查"
fi


PS:

svn用户权限统一管理(所有项目全调用/svn/conf下的authz和passwd)



# pwd

/svn/conf


# cat svnserve.conf |grep conf

password-db = ../../conf/passwd
authz-db = ../../conf/authz


# ls -l
总用量 16
-rw-r--r-- 1 root root 1106 10月 21 10:15 authz
-rw-r--r-- 1 root root  341 10月 21 08:37 passwd
-rw-r--r-- 1 root root  191 10月 21 08:22 post-commit
-rw-r--r-- 1 root root 2337 10月 20 16:34 svnserve.conf

钩子(sync是通用账户,钩子专用):
# cat post-commit
#!/bin/sh
#export LANG="zh_CN.UTF-8"
export LANG="en_US.UTF-8"
SVN=/usr/bin/svn
WEB=/data/htdocs/domain
$SVN update $WEB --no-auth-cache --non-interactive --username "sync" --password "sync"


由于svn第一次检索需要认证,如果不人工输入yes,就不会checkout,所以需要更改/root/.subversion/servers,将[global]下的store-plaintext-passwords=no的注释去掉,或者直接添加如下
# vim /root/.subversion/servers

[global]
store-plaintext-passwords = no

这样就没有任何提示,直接checkout,脚本全部自动完成













评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值