Last active
August 29, 2015 14:01
-
-
Save aleciogomes/296528da6a4003e7fc8b to your computer and use it in GitHub Desktop.
Nginx script
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
| #!/bin/sh | |
| # | |
| # used in https://gist.github.com/dannguyen/5415628 for CentOS | |
| # modification of: http://articles.slicehost.com/2009/2/2/centos-adding-an-nginx-init-script | |
| # | |
| # nginx - this script starts and stops the nginx daemon | |
| # | |
| # chkconfig: - 85 15 | |
| # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ | |
| # proxy and IMAP/POP3 proxy server | |
| # processname: nginx | |
| # config: /usr/local/nginx/conf/nginx.conf | |
| # pidfile: /usr/local/nginx/logs/nginx.pid | |
| # Source function library. | |
| . /etc/rc.d/init.d/functions | |
| # Source networking configuration. | |
| . /etc/sysconfig/network | |
| # Check that networking is up. | |
| [ "$NETWORKING" = "no" ] && exit 0 | |
| #nginx="/usr/local/sbin/nginx" | |
| nginx="/opt/nginx/sbin/nginx" | |
| prog=$(basename $nginx) | |
| #NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" | |
| NGINX_CONF_FILE="/opt/nginx/conf/nginx.conf" | |
| lockfile=/var/lock/subsys/nginx | |
| start() { | |
| [ -x $nginx ] || exit 5 | |
| [ -f $NGINX_CONF_FILE ] || exit 6 | |
| echo -n $"Starting $prog: " | |
| daemon $nginx -c $NGINX_CONF_FILE | |
| retval=$? | |
| echo | |
| [ $retval -eq 0 ] && touch $lockfile | |
| return $retval | |
| } | |
| stop() { | |
| echo -n $"Stopping $prog: " | |
| killproc $prog -QUIT | |
| retval=$? | |
| echo | |
| [ $retval -eq 0 ] && rm -f $lockfile | |
| return $retval | |
| } | |
| restart() { | |
| configtest || return $? | |
| stop | |
| start | |
| } | |
| reload() { | |
| configtest || return $? | |
| echo -n $"Reloading $prog: " | |
| killproc $nginx -HUP | |
| RETVAL=$? | |
| echo | |
| } | |
| force_reload() { | |
| restart | |
| } | |
| configtest() { | |
| $nginx -t -c $NGINX_CONF_FILE | |
| } | |
| rh_status() { | |
| status $prog | |
| } | |
| rh_status_q() { | |
| rh_status >/dev/null 2>&1 | |
| } | |
| case "$1" in | |
| start) | |
| rh_status_q && exit 0 | |
| $1 | |
| ;; | |
| stop) | |
| rh_status_q || exit 0 | |
| $1 | |
| ;; | |
| restart|configtest) | |
| $1 | |
| ;; | |
| reload) | |
| rh_status_q || exit 7 | |
| $1 | |
| ;; | |
| force-reload) | |
| force_reload | |
| ;; | |
| status) | |
| rh_status | |
| ;; | |
| condrestart|try-restart) | |
| rh_status_q || exit 0 | |
| ;; | |
| *) | |
| echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" | |
| exit 2 | |
| esac |
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
| # SSH into machine | |
| # Update packages | |
| sudo yum update | |
| # Create deploy user | |
| sudo adduser deploy | |
| # Install system-wide RVM | |
| \curl -sSL https://get.rvm.io | sudo bash -s stable | |
| # (with latest ruby version) | |
| \curl -sSL https://get.rvm.io | sudo bash -s stable --ruby | |
| # add users to rvm group | |
| usermod -a -G rvm ec2-user | |
| usermod -a -G rvm deploy | |
| # logout - login again | |
| exit | |
| # Create new gemset for app | |
| rvm gemset create <GEMSET NAME> | |
| rvm gemset use <GEMSET NAME> --default | |
| # Configure rubygems to not install docs | |
| echo 'gem: --no-ri --no-rdoc' > ~/.gemrc | |
| # install passenger + use passenger-nginx module to install nginx for us (compiled from source). | |
| gem install passenger | |
| sudo mkdir /opt/nginx/ | |
| sudo chown ec2-user /opt/nginx | |
| passenger-install-nginx-module | |
| # "install" nginx init.d script | |
| wget -O init-nginx.sh https://gist.githubusercontent.com/aleciogomes/296528da6a4003e7fc8b/raw/73967e4d8f1a0d11204a0f6d4ba47e1a14753550/nginx | |
| sudo mv init-nginx.sh /etc/init.d/nginx | |
| sudo chmod +x /etc/init.d/nginx | |
| sudo service nginx start | |
| # start nginx on boot | |
| sudo chkconfig nginx on | |
| # Install rails | |
| gem install rails | |
| # MySQL | |
| sudo yum groupinstall -y "MySQL Database" | |
| sudo service mysqld start | |
| sudo chkconfig mysqld on | |
| sudo mysql_secure_installation | |
| mysql -u root -p | |
| > CREATE USER 'APP-user'@'localhost' IDENTIFIED BY '<PASSWORD>'; | |
| > CREATE DATABASE `APP-db`; | |
| > GRANT ALL PRIVILEGES ON `APP-db`.* TO "APP-user"@"localhost"; | |
| > FLUSH PRIVILEGES; | |
| > exit | |
| # Directories | |
| sudo groupadd www | |
| sudo usermod -a -G www ec2-user | |
| sudo usermod -a -G www deploy | |
| exit # logout - login again | |
| sudo mkdir -p /var/www/mapptip | |
| sudo chown -R root:www /var/www | |
| sudo chmod 2775 /var/www | |
| find /var/www -type d -exec sudo chmod 2775 {} + | |
| find /var/www -type f -exec sudo chmod 0664 {} + | |
| # Configure and restart Nginx | |
| # Git | |
| sudo yum install -y git |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment