Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
a542f807
Commit
a542f807
authored
Oct 24, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5326 from Rovanion/init-fix
Made stop message make more sense, app_root now uses the user name.
parents
83878066
67a80d07
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
39 deletions
+67
-39
CHANGELOG
CHANGELOG
+2
-0
lib/support/init.d/gitlab
lib/support/init.d/gitlab
+65
-39
No files found.
CHANGELOG
View file @
a542f807
v 6.3.0
- Init script now waits for pids to appear after (re)starting before reporting status (Rovanion Luckey)
v 6.2.0
v 6.2.0
- Public project pages are now visible to everyone (files, issues, wik, etc.)
- Public project pages are now visible to everyone (files, issues, wik, etc.)
THIS MEANS YOUR ISSUES AND WIKI FOR PUBLIC PROJECTS ARE PUBLICLY VISIBLE AFTER THE UPGRADE
THIS MEANS YOUR ISSUES AND WIKI FOR PUBLIC PROJECTS ARE PUBLICLY VISIBLE AFTER THE UPGRADE
...
...
lib/support/init.d/gitlab
View file @
a542f807
...
@@ -20,8 +20,8 @@ RAILS_ENV="production"
...
@@ -20,8 +20,8 @@ RAILS_ENV="production"
# Script variable names should be lower-case not to conflict with internal
# Script variable names should be lower-case not to conflict with internal
# /bin/sh variables such as PATH, EDITOR or SHELL.
# /bin/sh variables such as PATH, EDITOR or SHELL.
app_root
=
"/home/git/gitlab"
app_user
=
"git"
app_user
=
"git"
app_root
=
"/home/
$app_user
/gitlab"
pid_path
=
"
$app_root
/tmp/pids"
pid_path
=
"
$app_root
/tmp/pids"
socket_path
=
"
$app_root
/tmp/sockets"
socket_path
=
"
$app_root
/tmp/sockets"
web_server_pid_path
=
"
$pid_path
/unicorn.pid"
web_server_pid_path
=
"
$pid_path
/unicorn.pid"
...
@@ -44,6 +44,7 @@ fi
...
@@ -44,6 +44,7 @@ fi
### Init Script functions
### Init Script functions
## Gets the pids from the files
check_pids
(){
check_pids
(){
if
!
mkdir
-p
"
$pid_path
"
;
then
if
!
mkdir
-p
"
$pid_path
"
;
then
echo
"Could not create the path
$pid_path
needed to store the pids."
echo
"Could not create the path
$pid_path
needed to store the pids."
...
@@ -62,12 +63,29 @@ check_pids(){
...
@@ -62,12 +63,29 @@ check_pids(){
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
sleep
0.1
;
i
=
$((
i+1
))
if
[
$((
i%10
))
=
0
]
;
then
echo
-n
"."
elif
[
$((
i
))
=
301
]
;
then
echo
"Waited 30s for the processes to write their pids, something probably went wrong."
exit
1
;
fi
done
echo
}
# We use the pids in so many parts of the script it makes sense to always check them.
# We use the pids in so many parts of the script it makes sense to always check them.
# Only after start() is run should the pids change. Sidekiq sets it's own pid.
# Only after start() is run should the pids change. Sidekiq sets it's own pid.
check_pids
check_pids
# Checks whether the different parts of the service are already running or not.
#
#
Checks whether the different parts of the service are already running or not.
check_status
(){
check_status
(){
check_pids
check_pids
# If the web server is running kill -0 $wpid returns true, or rather 0.
# If the web server is running kill -0 $wpid returns true, or rather 0.
...
@@ -86,7 +104,7 @@ check_status(){
...
@@ -86,7 +104,7 @@ check_status(){
fi
fi
}
}
#
Check for stale pids and remove them if necessary
#
# Check for stale pids and remove them if necessary.
check_stale_pids
(){
check_stale_pids
(){
check_status
check_status
# If there is a pid it is something else than 0, the service is running if
# If there is a pid it is something else than 0, the service is running if
...
@@ -94,7 +112,7 @@ check_stale_pids(){
...
@@ -94,7 +112,7 @@ check_stale_pids(){
if
[
"
$wpid
"
!=
"0"
-a
"
$web_status
"
!=
"0"
]
;
then
if
[
"
$wpid
"
!=
"0"
-a
"
$web_status
"
!=
"0"
]
;
then
echo
"Removing stale Unicorn web server pid. This is most likely caused by the web server crashing the last time it ran."
echo
"Removing stale Unicorn web server pid. This is most likely caused by the web server crashing the last time it ran."
if
!
rm
"
$web_server_pid_path
"
;
then
if
!
rm
"
$web_server_pid_path
"
;
then
echo
"Unable to remove stale pid, exiting"
echo
"Unable to remove stale pid, exiting
.
"
exit
1
exit
1
fi
fi
fi
fi
...
@@ -107,7 +125,7 @@ check_stale_pids(){
...
@@ -107,7 +125,7 @@ check_stale_pids(){
fi
fi
}
}
# If no parts of the service is running, bail out.
#
#
If no parts of the service is running, bail out.
exit_if_not_running
(){
exit_if_not_running
(){
check_stale_pids
check_stale_pids
if
[
"
$web_status
"
!=
"0"
-a
"
$sidekiq_status
"
!=
"0"
]
;
then
if
[
"
$web_status
"
!=
"0"
-a
"
$sidekiq_status
"
!=
"0"
]
;
then
...
@@ -116,86 +134,92 @@ exit_if_not_running(){
...
@@ -116,86 +134,92 @@ exit_if_not_running(){
fi
fi
}
}
#
Starts Unicorn and Sidekiq
.
#
# Starts Unicorn and Sidekiq if they're not running
.
start
()
{
start
()
{
check_stale_pids
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
echo
-n
"Starting GitLab Sidekiq"
elif
[
"
$sidekiq_status
"
!=
"0"
]
;
then
echo
-n
"Starting GitLab Unicorn"
fi
# Then check if the service is running. If it is: don't start again.
# Then check if the service is running. If it is: don't start again.
if
[
"
$web_status
"
=
"0"
]
;
then
if
[
"
$web_status
"
=
"0"
]
;
then
echo
"The Unicorn web server already running with pid
$wpid
, not restarting."
echo
"The Unicorn web server already running with pid
$wpid
, not restarting."
else
else
echo
"Starting the GitLab Unicorn web server..."
# Remove old socket if it exists
# Remove old socket if it exists
rm
-f
"
$socket_path
"
/gitlab.socket 2>/dev/null
rm
-f
"
$socket_path
"
/gitlab.socket 2>/dev/null
# Start the webserver
# Start the web
server
RAILS_ENV
=
$RAILS_ENV
script/web start
RAILS_ENV
=
$RAILS_ENV
script/web start
&
fi
fi
# If sidekiq is already running, don't start it again.
# If sidekiq is already running, don't start it again.
if
[
"
$sidekiq_status
"
=
"0"
]
;
then
if
[
"
$sidekiq_status
"
=
"0"
]
;
then
echo
"The Sidekiq job dispatcher is already running with pid
$spid
, not restarting"
echo
"The Sidekiq job dispatcher is already running with pid
$spid
, not restarting"
else
else
echo
"Starting the GitLab Sidekiq event dispatcher..."
RAILS_ENV
=
$RAILS_ENV
script/background_jobs start &
RAILS_ENV
=
$RAILS_ENV
script/background_jobs start
# We are sleeping a bit here because sidekiq is slow at writing it's pid
sleep
2
fi
fi
# Wait for the pids to be planted
wait_for_pids
# Finally check the status to tell wether or not GitLab is running
# Finally check the status to tell wether or not GitLab is running
status
print_
status
}
}
# Asks the Unicorn and the Sidekiq if they would be so kind as to stop, if not kills them.
#
#
Asks the Unicorn and the Sidekiq if they would be so kind as to stop, if not kills them.
stop
()
{
stop
()
{
exit_if_not_running
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 Sidekiq"
elif
[
"
$sidekiq_status
"
=
"0"
]
;
then
echo
-n
"Shutting down Unicorn"
fi
# If the Unicorn web server is running, tell it to stop;
# If the Unicorn web server is running, tell it to stop;
if
[
"
$web_status
"
=
"0"
]
;
then
if
[
"
$web_status
"
=
"0"
]
;
then
RAILS_ENV
=
$RAILS_ENV
script/web stop
RAILS_ENV
=
$RAILS_ENV
script/web stop
echo
"Stopping the GitLab Unicorn web server..."
stopping
=
true
else
echo
"The Unicorn web was not running, doing nothing."
fi
fi
# And do the same thing for the Sidekiq.
# And do the same thing for the Sidekiq.
if
[
"
$sidekiq_status
"
=
"0"
]
;
then
if
[
"
$sidekiq_status
"
=
"0"
]
;
then
printf
"Stopping Sidekiq job dispatcher."
RAILS_ENV
=
$RAILS_ENV
script/background_jobs stop
RAILS_ENV
=
$RAILS_ENV
script/background_jobs stop
stopping
=
true
else
echo
"The Sidekiq was not running, must have run out of breath."
fi
fi
# If something needs to be stopped, lets wait for it to stop. Never use SIGKILL in a script.
# If something needs to be stopped, lets wait for it to stop. Never use SIGKILL in a script.
while
[
"
$
stopping
"
=
"true
"
]
;
do
while
[
"
$
web_status
"
=
"0"
-o
"
$sidekiq_status
"
=
"0
"
]
;
do
sleep
1
sleep
1
check_status
check_status
if
[
"
$web_status
"
=
"0"
-o
"
$sidekiq_status
"
=
"0"
]
;
then
printf
"."
printf
"."
if
[
"
$web_status
"
!=
"0"
-a
"
$sidekiq_status
"
!=
"0"
]
;
then
else
printf
"
\n
"
printf
"
\n
"
break
break
fi
fi
done
done
sleep
1
sleep
1
# Cleaning up unused pids
# Cleaning up unused pids
rm
"
$web_server_pid_path
"
2>/dev/null
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" # Sidekiq seems to be cleaning up it's own pid.
status
print_
status
}
}
#
Returns the status of GitLab and it's components
#
# Prints the status of GitLab and it's components.
status
()
{
print_
status
()
{
check_status
check_status
if
[
"
$web_status
"
!=
"0"
-a
"
$sidekiq_status
"
!=
"0"
]
;
then
if
[
"
$web_status
"
!=
"0"
-a
"
$sidekiq_status
"
!=
"0"
]
;
then
echo
"GitLab is not running."
echo
"GitLab is not running."
return
return
fi
fi
if
[
"
$web_status
"
=
"0"
]
;
then
if
[
"
$web_status
"
=
"0"
]
;
then
echo
"The GitLab Unicorn webserver with pid
$wpid
is running."
echo
"The GitLab Unicorn web
server with pid
$wpid
is running."
else
else
printf
"The GitLab Unicorn webserver is
\0
33[31mnot running
\0
33[0m.
\n
"
printf
"The GitLab Unicorn web
server is
\0
33[31mnot running
\0
33[0m.
\n
"
fi
fi
if
[
"
$sidekiq_status
"
=
"0"
]
;
then
if
[
"
$sidekiq_status
"
=
"0"
]
;
then
echo
"The GitLab Sidekiq job dispatcher with pid
$spid
is running."
echo
"The GitLab Sidekiq job dispatcher with pid
$spid
is running."
...
@@ -207,6 +231,7 @@ status() {
...
@@ -207,6 +231,7 @@ status() {
fi
fi
}
}
## Tells unicorn to reload it's config and Sidekiq to restart
reload
(){
reload
(){
exit_if_not_running
exit_if_not_running
if
[
"
$wpid
"
=
"0"
]
;
then
if
[
"
$wpid
"
=
"0"
]
;
then
...
@@ -218,11 +243,12 @@ reload(){
...
@@ -218,11 +243,12 @@ reload(){
echo
"Done."
echo
"Done."
echo
"Restarting GitLab Sidekiq since it isn't capable of reloading its config..."
echo
"Restarting GitLab Sidekiq since it isn't capable of reloading its config..."
RAILS_ENV
=
$RAILS_ENV
script/background_jobs restart
RAILS_ENV
=
$RAILS_ENV
script/background_jobs restart
# Waiting 2 seconds for sidekiq to write it.
sleep
2
wait_for_pids
status
print_
status
}
}
## Restarts Sidekiq and Unicorn.
restart
(){
restart
(){
check_status
check_status
if
[
"
$web_status
"
=
"0"
-o
"
$sidekiq_status
"
=
"0"
]
;
then
if
[
"
$web_status
"
=
"0"
-o
"
$sidekiq_status
"
=
"0"
]
;
then
...
@@ -232,7 +258,7 @@ restart(){
...
@@ -232,7 +258,7 @@ restart(){
}
}
## Finally the input handling.
##
#
Finally the input handling.
case
"
$1
"
in
case
"
$1
"
in
start
)
start
)
...
@@ -248,7 +274,7 @@ case "$1" in
...
@@ -248,7 +274,7 @@ case "$1" in
reload
reload
;;
;;
status
)
status
)
status
print_
status
;;
;;
*
)
*
)
echo
"Usage: service gitlab {start|stop|restart|reload|status}"
echo
"Usage: service gitlab {start|stop|restart|reload|status}"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment