/etc/init.d/puma_a.sh
두 개의 스크립트 가 있고 /etc/init.d/puma_b.sh
동일한 구성을 가지고 있습니다. 이렇게 두 개의 스타트업을 설정해 보았으나 그 중 하나가 시작 시 로드되지 않습니다. 콘솔에서 수동으로 시작하면 작동합니다. 어떤 아이디어가 있나요?
root@site:~# update-rc.d puma_a.sh defaults 98
Adding system startup for /etc/init.d/puma_a.sh ...
/etc/rc0.d/K98puma_a.sh -> ../init.d/puma_a.sh
/etc/rc1.d/K98puma_a.sh -> ../init.d/puma_a.sh
/etc/rc6.d/K98puma_a.sh -> ../init.d/puma_a.sh
/etc/rc2.d/S98puma_a.sh -> ../init.d/puma_a.sh
/etc/rc3.d/S98puma_a.sh -> ../init.d/puma_a.sh
/etc/rc4.d/S98puma_a.sh -> ../init.d/puma_a.sh
/etc/rc5.d/S98puma_a.sh -> ../init.d/puma_a.sh
/etc/init.d/puma_a.sh
:
#! /bin/sh
### BEGIN INIT INFO
# Provides: pumacontrol
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Puma web server
### END INIT INFO
# Simple move this file into /etc/init.d/pumacontrol.sh
# Also make sure you `chmod +x pumacontrol.sh`.
# If you need to start puma at boot time run this in debian/ubuntu: update-rc.d pumacontrol.sh defaults
# It will create some links to execute /etc/init.d/pumacontrol.sh start at the begining
# I use this in a system where the rails app is running by a normal user, where puma is
# configured in PUMA_CONFIG_FILE. In PUMA_CONFIG_FILE is stated to create a pid file with the PID of
# puma in the PUMA_PID_FILE file. The socket where nginx is redirecting the web traffic and puma is
# listening is PUMA_SOCKET
# You need to specify a location for the PUMA_CONFIG_FILE
# /etc/init.d/puma_a.sh
PUMA_CONFIG_FILE=/var/www/site_a.com/current/config/puma.rb # WRITE HERE PUMA CONFIG FILE LOCATION
# strip out quotes, remove comments, initial spaces, and get only the filename
# if desired write here the path to the desired file for example:
# PUMA_PID_FILE=/path/foo.pid
PUMA_PID_FILE=/var/run/site_a.pid
PUMA_SOCKET=/var/run/site_a.sock
WORKING_DIR=/var/www/site_a.com/current
if [ $1 -a $2 ] ; then # If passed 2 params the second one should be the puma config file
PUMA_CONFIG_FILE=$2
fi
PUMA_CONFIGFILE_OWNER=`ls -l $PUMA_CONFIG_FILE |cut -d' ' -f3`
#------------------------ checkings -------------------------------------
if [ ! -r $PUMA_CONFIG_FILE ] ; then # if not readable
echo "File $PUMA_CONFIG_FILE not found or not readable"
echo "You should write in pumacontrol.sh the location of your config/puma.rb"
echo "or run this script like this 'pumacontrol.sh start /path/railsapp/config/puma.rb'"
exit 1
fi
if [ -z $PUMA_PID_FILE ] ; then # if empty string
echo "pidfile option in $PUMA_PID_FILE not found. You should write something like"
echo 'pidfile "/path/puma.pid"'
exit 1
fi
if [ -z $PUMA_SOCKET ] ; then # if empty string
echo "bind option in $PUMA_SOCKET not found. You should write something like"
echo 'bind "unix://path/railsAppName.sock"'
exit 1
fi
if [ -z $WORKING_DIR ] ; then # if empty string
echo "directory option in $WORKING_DIR not found. You should write something like"
echo "directory '/path/yourRailsAppRootDir/'"
exit 1
fi
#------------------------ functions -------------------------------------
# check if puma process is running
puma_is_running() {
if [ -S $PUMA_SOCKET ] ; then # if file exist and its a socket
if [ -r $PUMA_PID_FILE ] ; then # if file exist and readable
if cat $PUMA_PID_FILE | xargs pgrep -P > /dev/null ; then
return 0
else
echo "No puma process found"
fi
else
echo "No puma pid file found"
fi
else
echo "No puma socket found"
fi
return 1
}
#------------------------ script -------------------------------------
case "$1" in
start)
echo "Starting puma..."
if [ -e $PUMA_SOCKET ] ; then # if socket exists
rm -f $PUMA_SOCKET
echo "removed $PUMA_SOCKET"
fi
# Exec puma as the owner, so we need to be either root or the real owner"*
if [ `whoami` = $PUMA_CONFIGFILE_OWNER ] # owner
then
/bin/bash --login -c "(cd $WORKING_DIR && bundle exec puma -C $PUMA_CONFIG_FILE)" 2>&1 >> /var/log/site_a.log
elif [ `whoami` = root ] # root
then
su -l $PUMA_CONFIGFILE_OWNER -c "(cd $WORKING_DIR && bundle exec puma -C $PUMA_CONFIG_FILE)"
else # error
echo "you should be root or the owner of the file to have the gemset ready to start the rails stack"
fi
echo "done"
;;
stop)
if [ -e $PUMA_PID_FILE ] ; then # if pid file exists
echo "Stopping puma..."
/bin/bash --login -c " kill -s SIGTERM `cat $PUMA_PID_FILE` "
echo "Killed puma PID `cat $PUMA_PID_FILE`"
rm -f $PUMA_PID_FILE
echo "removed $PUMA_PID_FILE"
fi
if [ -e $PUMA_SOCKET ] ; then # if socket exists
rm -f $PUMA_SOCKET
echo "removed $PUMA_SOCKET"
fi
echo "done"
;;
restart)
if puma_is_running ; then
echo "Hot-restarting puma..."
if [ -e $PUMA_PID_FILE ] ; then
/bin/bash --login -c " kill -s SIGUSR2 `cat $PUMA_PID_FILE` "
echo "Killed puma PID `cat $PUMA_PID_FILE`"
fi
echo "Doublechecking the process restart..."
sleep 5
if puma_is_running ; then
echo "done"
exit 0
else
echo "Puma restart failed :/"
exit 1 # return error
fi
fi
echo "Trying cold reboot"
$0 start
;;
status)
if puma_is_running ; then
echo "puma is running"
exit 0
else
echo "puma is not running"
exit 1 # return error
fi
;;
*)
echo "Usage: script/puma.sh {start|stop|restart|status}" >&2
;;
esac
그리고
ls -l /etc/init.d/puma
-rwxr-xr-x 1 root root 4995 Sep 19 20:26 puma_a.sh
-rwxr-xr-x 1 root root 4985 Sep 19 19:21 puma_b.sh
고쳐 쓰다:로그를 보면 puma가 시작되지 않는 것을 알 수 있습니다. /etc/init.d/puma_a.sh start
수동으로 할 때 작동하기 때문에 이상합니다 .
[1791] Puma starting in cluster mode...
[1791] * Version 2.5.1, codename: Astronaut Shoelaces
[1791] * Min threads: 8, max threads: 32
[1791] * Environment: production
[1791] * Process workers: 6
[1791] * Preloading application
[1791] ! Unable to load application
업데이트 2: 결과diff puma_{a,b}.sh
93c93
< /bin/bash --login -c "(cd $WORKING_DIR && bundle exec puma -C $PUMA_CONFIG_FILE)" 2>&1 >> /var/log/site_a.log
---
> /bin/bash --login -c "(cd $WORKING_DIR && bundle exec puma -C $PUMA_CONFIG_FILE)" 2>&1 >> /var/log/site_b.log
96c96
< su -l $PUMA_CONFIGFILE_OWNER -c "(cd $WORKING_DIR && bundle exec puma -C $PUMA_CONFIG_FILE)" 2>&1 >> /var/log/site_a.log
---
> su -l $PUMA_CONFIGFILE_OWNER -c "(cd $WORKING_DIR && bundle exec puma -C $PUMA_CONFIG_FILE)"
답변1
먼저 스크립트를 실행 가능하게 만들어야 합니다.
chmod +x puma_a.sh
실행 권한이 없는 스크립트를 시작 시퀀스에 넣는 것은 무시됩니다.