Update init scripts.
This commit is contained in:
parent
089aa2de2b
commit
f3b57ce677
5 changed files with 137 additions and 22 deletions
2
Procfile
2
Procfile
|
@ -1,3 +1,3 @@
|
|||
web: bundle exec unicorn_rails -p ${PORT:="3000"} -E ${RAILS_ENV:="development"} -c ${UNICORN_CONFIG:="config/unicorn.rb"}
|
||||
worker: bundle exec sidekiq -q post_receive -q mailer -q archive_repo -q system_hook -q project_web_hook -q gitlab_shell -q incoming_email -q common -q default
|
||||
mail_room: bundle exec mail_room -q -c config/mail_room.yml
|
||||
# mail_room: bundle exec mail_room -q -c config/mail_room.yml
|
||||
|
|
|
@ -37,7 +37,7 @@ start_no_deamonize()
|
|||
|
||||
start_sidekiq()
|
||||
{
|
||||
bundle exec sidekiq -q post_receive -q mailer -q archive_repo -q system_hook -q project_web_hook -q gitlab_shell -q common -q default -e $RAILS_ENV -P $sidekiq_pidfile $@ >> $sidekiq_logfile 2>&1
|
||||
bundle exec sidekiq -q post_receive -q mailer -q archive_repo -q system_hook -q project_web_hook -q gitlab_shell -q incoming_email -q common -q default -e $RAILS_ENV -P $sidekiq_pidfile $@ >> $sidekiq_logfile 2>&1
|
||||
}
|
||||
|
||||
load_ok()
|
||||
|
|
51
bin/mail_room
Executable file
51
bin/mail_room
Executable file
|
@ -0,0 +1,51 @@
|
|||
#!/bin/sh
|
||||
|
||||
cd $(dirname $0)/..
|
||||
app_root=$(pwd)
|
||||
|
||||
mail_room_pidfile="$app_root/tmp/pids/mail_room.pid"
|
||||
mail_room_config="$app_root/config/mail_room.yml"
|
||||
|
||||
get_mail_room_pid()
|
||||
{
|
||||
local pid=$(cat $mail_room_pidfile)
|
||||
if [ -z "$pid" ] ; then
|
||||
echo "Could not find a PID in $mail_room_pidfile"
|
||||
exit 1
|
||||
fi
|
||||
mail_room_pid=$pid
|
||||
}
|
||||
|
||||
start()
|
||||
{
|
||||
bundle exec mail_room -q -c $mail_room_config
|
||||
PID=$!
|
||||
echo $PID > $mail_room_pidfile
|
||||
}
|
||||
|
||||
stop()
|
||||
{
|
||||
get_mail_room_pid
|
||||
kill -QUIT $mail_room_pid
|
||||
}
|
||||
|
||||
reload()
|
||||
{
|
||||
get_mail_room_pid
|
||||
kill -USR2 $mail_room_pid
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
reload)
|
||||
reload
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|reload}"
|
||||
;;
|
||||
esac
|
|
@ -35,6 +35,8 @@ pid_path="$app_root/tmp/pids"
|
|||
socket_path="$app_root/tmp/sockets"
|
||||
web_server_pid_path="$pid_path/unicorn.pid"
|
||||
sidekiq_pid_path="$pid_path/sidekiq.pid"
|
||||
mail_room_enabled=false
|
||||
mail_room_pid_path="$pid_path/mail_room.pid"
|
||||
shell_path="/bin/bash"
|
||||
|
||||
# Read configuration variable file if it is present
|
||||
|
@ -70,13 +72,20 @@ check_pids(){
|
|||
else
|
||||
spid=0
|
||||
fi
|
||||
if [ "$mail_room_enabled" = true ]; then
|
||||
if [ -f "$mail_room_pid_path" ]; then
|
||||
mpid=$(cat "$mail_room_pid_path")
|
||||
else
|
||||
mpid=0
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
## Called when we have started the two processes and are waiting for their pid files.
|
||||
wait_for_pids(){
|
||||
# We are sleeping a bit here mostly because sidekiq is slow at writing it's pid
|
||||
i=0;
|
||||
while [ ! -f $web_server_pid_path -o ! -f $sidekiq_pid_path ]; do
|
||||
while [ ! -f $web_server_pid_path -o ! -f $sidekiq_pid_path -o [ "$mail_room_enabled" = true && ! -f $mail_room_pid_path ] ]; do
|
||||
sleep 0.1;
|
||||
i=$((i+1))
|
||||
if [ $((i%10)) = 0 ]; then
|
||||
|
@ -111,7 +120,13 @@ check_status(){
|
|||
else
|
||||
sidekiq_status="-1"
|
||||
fi
|
||||
if [ $web_status = 0 -a $sidekiq_status = 0 ]; then
|
||||
if [ "$mail_room_enabled" = true && $mpid -ne 0 ]; then
|
||||
kill -0 "$mpid" 2>/dev/null
|
||||
mail_room_status="$?"
|
||||
else
|
||||
mail_room_status="-1"
|
||||
fi
|
||||
if [ $web_status = 0 -a $sidekiq_status = 0 -a [ "$mail_room_enabled" != true || $mail_room_status = 0 ] ]; then
|
||||
gitlab_status=0
|
||||
else
|
||||
# http://refspecs.linuxbase.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
|
||||
|
@ -139,12 +154,19 @@ check_stale_pids(){
|
|||
exit 1
|
||||
fi
|
||||
fi
|
||||
if [ "$mail_room_enabled" = true && "$mpid" != "0" -a "$mail_room_status" != "0" ]; then
|
||||
echo "Removing stale MailRoom job dispatcher pid. This is most likely caused by MailRoom crashing the last time it ran."
|
||||
if ! rm "$mail_room_pid_path"; then
|
||||
echo "Unable to remove stale pid, exiting"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
## If no parts of the service is running, bail out.
|
||||
exit_if_not_running(){
|
||||
check_stale_pids
|
||||
if [ "$web_status" != "0" -a "$sidekiq_status" != "0" ]; then
|
||||
if [ "$web_status" != "0" -a "$sidekiq_status" != "0" -a [ "$mail_room_enabled" = true && "$mail_room_status" != "0" ] ]; then
|
||||
echo "GitLab is not running."
|
||||
exit
|
||||
fi
|
||||
|
@ -154,13 +176,15 @@ exit_if_not_running(){
|
|||
start_gitlab() {
|
||||
check_stale_pids
|
||||
|
||||
if [ "$web_status" != "0" -a "$sidekiq_status" != "0" ]; then
|
||||
echo -n "Starting both the GitLab Unicorn and Sidekiq"
|
||||
elif [ "$web_status" != "0" ]; then
|
||||
if [ "$web_status" != "0" ]; then
|
||||
echo -n "Starting GitLab Unicorn"
|
||||
elif [ "$sidekiq_status" != "0" ]; then
|
||||
fi
|
||||
if [ "$sidekiq_status" != "0" ]; then
|
||||
echo -n "Starting GitLab Sidekiq"
|
||||
fi
|
||||
if [ "$mail_room_enabled" = true && "$mail_room_status" != "0" ]; then
|
||||
echo -n "Starting GitLab MailRoom"
|
||||
fi
|
||||
|
||||
# Then check if the service is running. If it is: don't start again.
|
||||
if [ "$web_status" = "0" ]; then
|
||||
|
@ -179,22 +203,33 @@ start_gitlab() {
|
|||
RAILS_ENV=$RAILS_ENV bin/background_jobs start &
|
||||
fi
|
||||
|
||||
if [ "$mail_room_enabled" = true ]; then
|
||||
# If MailRoom is already running, don't start it again.
|
||||
if [ "$mail_room_status" = "0" ]; then
|
||||
echo "The MailRoom email processor is already running with pid $spid, not restarting"
|
||||
else
|
||||
RAILS_ENV=$RAILS_ENV bin/mail_room start &
|
||||
fi
|
||||
fi
|
||||
|
||||
# Wait for the pids to be planted
|
||||
wait_for_pids
|
||||
# Finally check the status to tell wether or not GitLab is running
|
||||
print_status
|
||||
}
|
||||
|
||||
## Asks the Unicorn and the Sidekiq if they would be so kind as to stop, if not kills them.
|
||||
## Asks Unicorn, Sidekiq and MailRoom if they would be so kind as to stop, if not kills them.
|
||||
stop_gitlab() {
|
||||
exit_if_not_running
|
||||
|
||||
if [ "$web_status" = "0" -a "$sidekiq_status" = "0" ]; then
|
||||
echo -n "Shutting down both Unicorn and Sidekiq"
|
||||
elif [ "$web_status" = "0" ]; then
|
||||
echo -n "Shutting down Unicorn"
|
||||
elif [ "$sidekiq_status" = "0" ]; then
|
||||
echo -n "Shutting down Sidekiq"
|
||||
if [ "$web_status" = "0" ]; then
|
||||
echo -n "Shutting down GitLab Unicorn"
|
||||
fi
|
||||
if [ "$sidekiq_status" = "0" ]; then
|
||||
echo -n "Shutting down GitLab Sidekiq"
|
||||
fi
|
||||
if [ "$mail_room_enabled" = true && "$mail_room_status" = "0" ]; then
|
||||
echo -n "Shutting down GitLab MailRoom"
|
||||
fi
|
||||
|
||||
# If the Unicorn web server is running, tell it to stop;
|
||||
|
@ -205,13 +240,17 @@ stop_gitlab() {
|
|||
if [ "$sidekiq_status" = "0" ]; then
|
||||
RAILS_ENV=$RAILS_ENV bin/background_jobs stop
|
||||
fi
|
||||
# And do the same thing for the MailRoom.
|
||||
if [ "$mail_room_enabled" = true && "$mail_room_status" = "0" ]; then
|
||||
RAILS_ENV=$RAILS_ENV bin/mail_room stop
|
||||
fi
|
||||
|
||||
# If something needs to be stopped, lets wait for it to stop. Never use SIGKILL in a script.
|
||||
while [ "$web_status" = "0" -o "$sidekiq_status" = "0" ]; do
|
||||
while [ "$web_status" = "0" -o "$sidekiq_status" = "0" -o [ "$mail_room_enabled" = true && "$mail_room_status" = "0" ] ]; do
|
||||
sleep 1
|
||||
check_status
|
||||
printf "."
|
||||
if [ "$web_status" != "0" -a "$sidekiq_status" != "0" ]; then
|
||||
if [ "$web_status" != "0" -a "$sidekiq_status" != "0" -a [ "$mail_room_enabled" != true || "$mail_room_status" != "0" ] ]; then
|
||||
printf "\n"
|
||||
break
|
||||
fi
|
||||
|
@ -220,7 +259,10 @@ stop_gitlab() {
|
|||
sleep 1
|
||||
# Cleaning up unused pids
|
||||
rm "$web_server_pid_path" 2>/dev/null
|
||||
# rm "$sidekiq_pid_path" # Sidekiq seems to be cleaning up it's own pid.
|
||||
# rm "$sidekiq_pid_path" 2>/dev/null # Sidekiq seems to be cleaning up it's own pid.
|
||||
if [ "$mail_room_enabled" = true ]; then
|
||||
rm "$mail_room_pid_path" 2>/dev/null
|
||||
fi
|
||||
|
||||
print_status
|
||||
}
|
||||
|
@ -228,7 +270,7 @@ stop_gitlab() {
|
|||
## Prints the status of GitLab and it's components.
|
||||
print_status() {
|
||||
check_status
|
||||
if [ "$web_status" != "0" -a "$sidekiq_status" != "0" ]; then
|
||||
if [ "$web_status" != "0" -a "$sidekiq_status" != "0" -a [ "$mail_room_enabled" != true || "$mail_room_status" != "0" ] ]; then
|
||||
echo "GitLab is not running."
|
||||
return
|
||||
fi
|
||||
|
@ -242,7 +284,14 @@ print_status() {
|
|||
else
|
||||
printf "The GitLab Sidekiq job dispatcher is \033[31mnot running\033[0m.\n"
|
||||
fi
|
||||
if [ "$web_status" = "0" -a "$sidekiq_status" = "0" ]; then
|
||||
if [ "$mail_room_enabled" = true ]; then
|
||||
if [ "$mail_room_status" = "0" ]; then
|
||||
echo "The GitLab MailRoom email processor with pid $spid is running."
|
||||
else
|
||||
printf "The GitLab MailRoom email processor is \033[31mnot running\033[0m.\n"
|
||||
fi
|
||||
end
|
||||
if [ "$web_status" = "0" -a "$sidekiq_status" = "0" -a [ "$mail_room_enabled" != true || "$mail_room_status" = "0" ] ]; then
|
||||
printf "GitLab and all its components are \033[32mup and running\033[0m.\n"
|
||||
fi
|
||||
}
|
||||
|
@ -257,9 +306,15 @@ reload_gitlab(){
|
|||
printf "Reloading GitLab Unicorn configuration... "
|
||||
RAILS_ENV=$RAILS_ENV bin/web reload
|
||||
echo "Done."
|
||||
|
||||
echo "Restarting GitLab Sidekiq since it isn't capable of reloading its config..."
|
||||
RAILS_ENV=$RAILS_ENV bin/background_jobs restart
|
||||
|
||||
if [ "$mail_room_enabled" != true ]; then
|
||||
echo "Restarting GitLab MailRoom since it isn't capable of reloading its config..."
|
||||
RAILS_ENV=$RAILS_ENV bin/mail_room restart
|
||||
fi
|
||||
|
||||
wait_for_pids
|
||||
print_status
|
||||
}
|
||||
|
@ -267,7 +322,7 @@ reload_gitlab(){
|
|||
## Restarts Sidekiq and Unicorn.
|
||||
restart_gitlab(){
|
||||
check_status
|
||||
if [ "$web_status" = "0" -o "$sidekiq_status" = "0" ]; then
|
||||
if [ "$web_status" = "0" -o "$sidekiq_status" = "0" -o [ "$mail_room_enabled" = true && "$mail_room_status" = "0" ] ]; then
|
||||
stop_gitlab
|
||||
fi
|
||||
start_gitlab
|
||||
|
|
|
@ -30,6 +30,15 @@ web_server_pid_path="$pid_path/unicorn.pid"
|
|||
# The default is "$pid_path/sidekiq.pid"
|
||||
sidekiq_pid_path="$pid_path/sidekiq.pid"
|
||||
|
||||
# mail_room_enabled specifies whether mail_room, which is used to process incoming email, is enabled.
|
||||
# This is required for the Reply by email feature.
|
||||
# The default is "false"
|
||||
mail_room_enabled=false
|
||||
|
||||
# mail_room_pid_path defines the path in which to create the pid file for mail_room
|
||||
# The default is "$pid_path/mail_room.pid"
|
||||
mail_room_pid_path="$pid_path/mail_room.pid"
|
||||
|
||||
# shell_path defines the path of shell for "$app_user" in case you are using
|
||||
# shell other than "bash"
|
||||
# The default is "/bin/bash"
|
||||
|
|
Loading…
Reference in a new issue