Created
June 27, 2014 05:38
-
-
Save mikesorae/218ba3b18933d879f29b to your computer and use it in GitHub Desktop.
prepare new user and config file for nginx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bash/bin | |
if [ $# != 2 ]; then | |
echo "usage: $0 app_name app_port" 1>&2 | |
exit 0 | |
fi | |
app_name=$1 | |
port=$2 | |
echo "checking the port" | |
port_used=`lsof -iTCP:${port} | wc -c` | |
if [ $port_used -ne 0 ]; then | |
echo "the port is already used" | |
exit 1 | |
fi | |
echo "checking the user" | |
user_exists=false | |
getent passwd $app_name >/dev/null 2>&1 && user_exists=true | |
if $user_exists; then | |
echo "this user already exists" | |
exit 1 | |
fi | |
echo "preparing user for the site" | |
useradd $app_name | |
gpasswd -a nginx $app_name | |
echo "preparing setting for nginx" | |
nginx_conf="/opt/nginx/conf" | |
cp $nginx_conf/rails_template.conf $nginx_conf/$app_name.conf | |
sed -i -E "s/\\\$PORT/${port}/" $nginx_conf/$app_name.conf | |
sed -i -E "s/\\\$APP_HOME/${app_name}\/${app_name}\/public/" $nginx_conf/$app_name.conf | |
sed -i -E "s/(#app_conf_setting)/\1\n include ${app_name}.conf;/" /opt/nginx/conf/nginx.conf | |
service nginx restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
echo 1>&2
exit 1
?