puma 配置,啟動指令碼

來源:互聯網
上載者:User



配置: 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

啟動開關: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


初始檔案:

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}`




工具檔案 function

#! /usr/bin/env bashfunction assert_process_from_name_not_exist(){  local pid  pid=$(ps aux|grep $1|grep -v grep|awk '{print $2}')  if [ "$pid" ];then  echo "已經有一個 $1 進程在運行"  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)" ]; then      echo "$1 pid_file 中記錄的 pid 還在運行"      exit 5    fi  fi}function check_run_status_from_pid_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[0m]"  else    echo -e "$service_name  [\e[1;31mnot running\e[0m]"  fi}function get_sh_dir_path(){  echo -n $(cd "$(dirname "$0")"; pwd)}function command_status(){  if [ $? == 0 ];then    echo -e "[\e[1;32msuccess\e[0m]"  else    echo -e "[\e[1;31mfail\e[0m]"  fi}function create_file(){  local file_name;  file_name=$1  if [ -d file_name ]; then    echo "Directory Exists!"  else      touch file_name  fi}



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.