Puma configuration and startup script

Source: Internet
Author: User

Configuration: puma_server_conf.rb

#!/usr/bin/env pumaapplication_path = '/srv/rorapps/discount_service'directory application_pathenvironment 'development'daemonize truepidfile "#{application_path}/tmp/pids/puma_4000.pid"state_path "#{application_path}/tmp/pids/puma_4000.state"stdout_redirect "#{application_path}/log/puma_4000.stdout.log", "#{application_path}/log/puma_4000.stderr.log"port 4000workers 8
Start switch: puma. sh
#! /usr/bin/env bashcurrent_path=`cd "$(dirname "$0")"; pwd`. $current_path/function.shpuma_file=$current_path/../puma_conf/puma_service_4000.rbpuma_pid=$current_path/../../tmp/pids/puma_4000.pidecho "######### info #############"echo "PUMA DISCOUNT SERVICE 4000"echo "## $puma_file ## $puma_pid ##"echo "############################"case "$1" in  start)    puma -C $puma_file    echo "puma_service_4000 start ............... $(command_status)"  ;;  status)    check_run_status_from_pid_file $puma_pid 'puma'  ;;  stop)    kill -s SIGTERM `cat $puma_pid`    echo "puma_service_4000 stop ................ $(command_status)"  ;;  restart)    # $0 stop    # sleep 1    # $0 start    kill -s SIGUSR2 `cat $puma_pid`  ;;  *)    echo "tip:(start|stop|restart|status)"    exit 5  ;;esacexit 0
Initial file:
MRS_DATA_PATH=`ruby $current_path/parse_property.rb MRS_DATA_PATH`rails_env=`ruby $current_path/parse_property.rb RAILS_ENV`processor_pid=$MRS_DATA_PATH/pids/sidekiq.pidlog_file=$MRS_DATA_PATH/logs/sidekiq.logstart:create_file $processor_pidcreate_file $log_file
parse_property.rb
require "yaml"yaml: MRS_DATA_PATH : $HOME/DISCOUNT_SERVICE_DATA   RAILS_ENV : developmentconfig = YAML.load_file(File.expand_path("../property.yaml",__FILE__))key = ARGV[0]value = config[key]value = value.gsub(/\/$/,"")if "MRS_DATA_PATH" == key  `mkdir -p #{value}/logs`  `mkdir -p #{value}/sockets`  `mkdir -p #{value}/pids`endputs `echo #{value}` 

Tool file function

#! /Usr/bin/env bashfunction assert_process_from_name_not_exist () {local pid =$ (ps aux | grep $1 | grep-v grep | awk '{print $2 }') if ["$ pid"]; then echo "already has a $1 process running" exit 5 fi} function assert_process_from_pid_file_not_exist () {local pid; if [-f $1]; then pid = $ (cat $1) if [$ pid] & ["$ (ps $ pid | grep-v PID)"]; the pid recorded in then echo "$1 pid_file is still running" exit 5 fi} function check_run_status_from_p Id_file () {local pid; local service_name; service_name = $2 if [-f $1]; then pid =$ (cat $1) fi if [$ pid] & ["$ (ps $ pid | grep-v PID)"]; then echo-e "$ service_name [\ e [1; 32mrunning \ e [0 m] "else echo-e" $ service_name [\ e [1; 31 mnot running \ e [0 m] "fi} function get_sh_dir_path () {echo-n $ (cd "$ (dirname" $0 ")"; pwd)} function command_status () {if [$? = 0]; then echo-e "[\ e [1; 32msuccess \ e [0 m]" else echo-e "[\ e [1; 31mfail \ e [0 m] "fi} function create_file () {local file_name; file_name = $1 if [-d file_name]; then echo" Directory Exists! "Else touch file_name fi}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.