puma 配置,启动脚本

版权声明:本文为博主原创文章,未经博主同意不得转载。 https://blog.csdn.net/menxu_work/article/details/24547923



配置: puma_server_conf.rb

#!/usr/bin/env puma

application_path = '/srv/rorapps/discount_service'
directory application_path
environment 'development'
daemonize true
pidfile "#{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 4000
workers 8

启动开关:puma.sh


#! /usr/bin/env bash
current_path=`cd "$(dirname "$0")"; pwd`
. $current_path/function.sh

puma_file=$current_path/../puma_conf/puma_service_4000.rb
puma_pid=$current_path/../../tmp/pids/puma_4000.pid

echo "######### 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
  ;;
esac
exit 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.pid
log_file=$MRS_DATA_PATH/logs/sidekiq.log

start:
create_file $processor_pid
create_file $log_file

parse_property.rb
require "yaml"

yaml: MRS_DATA_PATH : $HOME/DISCOUNT_SERVICE_DATA   RAILS_ENV : development
config = 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`
end


puts `echo #{value}`




工具文件 function

#! /usr/bin/env bash

function 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;32mrunninge[0m]"
  else
    echo -e "$service_name  [e[1;31mnot runninge[0m]"
  fi
}

function get_sh_dir_path()
{
  echo -n $(cd "$(dirname "$0")"; pwd)
}

function command_status()
{
  if [ $? == 0 ];then
    echo -e "[e[1;32msuccesse[0m]"
  else
    echo -e "[e[1;31mfaile[0m]"
  fi
}


function create_file()
{
  local file_name;
  file_name=$1
  if [ -d file_name ]; then
    echo "Directory Exists!"
  else  
    touch file_name
  fi
}



原文地址:https://www.cnblogs.com/ldxsuanfa/p/10050956.html