现在的位置: 首页 > 综合 > 正文

puma 配置,启动脚本

2018年09月08日 ⁄ 综合 ⁄ 共 2503字 ⁄ 字号 评论关闭

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

抱歉!评论已关闭.