Skip to content

Instantly share code, notes, and snippets.

@likai24
Created June 23, 2016 04:31
Show Gist options
  • Save likai24/acc66dd9d392559575fd306d03441313 to your computer and use it in GitHub Desktop.
Save likai24/acc66dd9d392559575fd306d03441313 to your computer and use it in GitHub Desktop.
一个使用模板脚本tpl.sh的例子
#!/usr/bin/env bash
# This file is to setup nginx for php application
# @Version : 0.0.1
# @Usage : ./setup.sh [appname] [server_name] [port] [fpm_port]
# @Example : ./setup.sh oa_attr attr.meikecheng.com 80 9023
#
set -o pipefail
set -o errexit
# set -o xtrace
source ../common/tpl.sh
__ETC__="/etc"
__NGINX_HOME__="${__ETC__}/nginx"
__SITES_AVAIL__="${__NGINX_HOME__}/sites-available"
__SITES_EN__="${__NGINX_HOME__}/sites-enabled"
__DEFAULT_ROOT__="/www/data"
function setup_nginx(){
local appname="$1"; shift
local server_name="${1:-*}"; shift
local port="${1:-80}";shift
local fpm_port="${1:-9020}";
local tpl="nginx.tpl"
local surffix="conf"
local user="www-data"
local group="www-data"
local root="${__DEFAULT_ROOT__}/${appname}/web";
local available="${__SITES_AVAIL__}/${appname}.${surffix}"
render "${tpl}" > "${available}"
sed -e "s/\${appname}/${appname}/" \
-e "s/\${server_name}/${server_name}/" \
-e "s|\${root}|${root}|" \
-e "s/\${port}/${port}/" \
-e "s/\${fpm_port}/${fpm_port}/" \
"${tpl}" > "${available}"
ln -sf "${available}" "${__SITES_EN__}"
}
function main(){
local appname=$1; shift
local server_name=$1; shift
local port=$1; shift
local fpm_port=$1;
setup_nginx $appname $server_name $port $fpm_port
echo "Nginx is setup for ${appname} successfully ${server_name} with phpfpm port ${fpm_port}"
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment