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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
df9e1db9
Commit
df9e1db9
authored
Aug 27, 2013
by
Rovanion
Committed by
Rovanion Luckey
Aug 27, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrote init script.
parent
79f0858a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
175 additions
and
78 deletions
+175
-78
CHANGELOG
CHANGELOG
+1
-0
lib/support/init.d/gitlab
lib/support/init.d/gitlab
+174
-78
No files found.
CHANGELOG
View file @
df9e1db9
v 6.1.0
v 6.1.0
- Rewrite: Init script now less prone to errors and keeps better track of the service.
- Link issues, merge requests, and commits when they reference each other with GFM
- Link issues, merge requests, and commits when they reference each other with GFM
- Close issues automatically when pushing commits with a special message
- Close issues automatically when pushing commits with a special message
...
...
lib/support/init.d/gitlab
100644 → 100755
View file @
df9e1db9
#! /bin/
ba
sh
#! /bin/sh
# GITLAB
# GITLAB
# Maintainer: @randx
# Maintainer: @randx
# Authors: rovanion.luckey@gmail.com, @randx
# App Version: 6.0
# App Version: 6.0
### BEGIN INIT INFO
### BEGIN INIT INFO
...
@@ -14,102 +15,198 @@
...
@@ -14,102 +15,198 @@
# Description: GitLab git repository management
# Description: GitLab git repository management
### END INIT INFO
### END INIT INFO
### Environment variables
RAILS_ENV
=
"production"
APP_ROOT
=
"/home/git/gitlab"
# Script variable names should be lower-case not to conflict with internal
APP_USER
=
"git"
# /bin/sh variables such as PATH, EDITOR or SHELL.
DAEMON_OPTS
=
"-c
$APP_ROOT
/config/unicorn.rb -E production"
app_root
=
"/home/gitlab/gitlab"
PID_PATH
=
"
$APP_ROOT
/tmp/pids"
app_user
=
"gitlab"
SOCKET_PATH
=
"
$APP_ROOT
/tmp/sockets"
unicorn_conf
=
"
$app_root
/config/unicorn.rb"
WEB_SERVER_PID
=
"
$PID_PATH
/unicorn.pid"
pid_path
=
"
$app_root
/tmp/pids"
SIDEKIQ_PID
=
"
$PID_PATH
/sidekiq.pid"
socket_path
=
"
$app_root
/tmp/sockets"
STOP_SIDEKIQ
=
"RAILS_ENV=production bundle exec rake sidekiq:stop"
web_server_pid_path
=
"
$pid_path
/unicorn.pid"
START_SIDEKIQ
=
"RAILS_ENV=production bundle exec rake sidekiq:start"
sidekiq_pid_path
=
"
$pid_path
/sidekiq.pid"
NAME
=
"gitlab"
DESC
=
"GitLab service"
check_pid
(){
### Here ends user configuration ###
if
[
-f
$WEB_SERVER_PID
]
;
then
PID
=
`
cat
$WEB_SERVER_PID
`
SPID
=
`
cat
$SIDEKIQ_PID
`
# Switch to the app_user if it is not he/she who is running the script.
STATUS
=
`
ps aux |
grep
$PID
|
grep
-v
grep
|
wc
-l
`
if
[
"
$USER
"
!=
"
$app_user
"
]
;
then
sudo
-u
"
$app_user
"
-H
/etc/init.d/gitlab
"
$@
"
;
exit
;
fi
# Switch to the gitlab path, if it fails exit with an error.
if
!
cd
"
$app_root
"
;
then
echo
"Failed to cd into
$app_root
, exiting!"
;
exit
1
fi
### Init Script functions
check_pids
(){
if
!
mkdir
-p
"
$pid_path
"
;
then
echo
"Could not create the path
$pid_path
needed to store the pids."
exit
1
fi
# If there exists a file which should hold the value of the Unicorn pid: read it.
if
[
-f
"
$web_server_pid_path
"
]
;
then
wpid
=
$(
cat
"
$web_server_pid_path
"
)
else
else
STATUS
=
0
wpid
=
0
PID
=
0
fi
if
[
-f
"
$sidekiq_pid_path
"
]
;
then
spid
=
$(
cat
"
$sidekiq_pid_path
"
)
else
spid
=
0
fi
}
# 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.
check_pids
# Checks wether the different parts of the server is already running or not.
check_status
(){
check_pids
# If the web server is running kill -0 $wpid returns true, or rather 0.
# Checks of *_status should only check for == 0 or != 0, never anything else.
if
[
$wpid
-ne
0
]
;
then
kill
-0
"
$wpid
"
2>/dev/null
web_status
=
"
$?
"
fi
if
[
$spid
-ne
0
]
;
then
kill
-0
"
$spid
"
2>/dev/null
sidekiq_status
=
"
$?
"
fi
}
# Check for stale pids and remove them if necessary
check_stale_pids
(){
check_status
# If there is a pid it is something else than 0, the service is running if
# *_status is == 0.
if
[
"
$wpid
"
!=
"0"
-a
"
$web_status
"
!=
"0"
]
;
then
echo
"Found stale Unicorn web server pid, removing. This is most likely caused by the web server crashing the last time it ran."
rm
"
$web_server_pid_path
"
fi
if
[
"
$spid
"
!=
"0"
-a
"
$sidekiq_status
"
!=
"0"
]
;
then
echo
"Found stale Sidekiq web server pid, removing. This is most likely caused by the Sidekiq crashing the last time it ran."
rm
"
$sidekiq_pid_path
"
fi
fi
}
}
execute
()
{
# If no parts of the service is running, bail out.
sudo
-u
$APP_USER
-H
bash
-l
-c
"
$1
"
check_not_running
(){
check_stale_pids
if
[
"
$web_status
"
!=
"0"
-a
"
$sidekiq_status
"
!=
"0"
]
;
then
echo
"GitLab is not running."
exit
fi
}
}
# Starts Unicorn and Sidekiq.
start
()
{
start
()
{
cd
$APP_ROOT
check_stale_pids
check_pid
if
[
"
$PID
"
-ne
0
-a
"
$STATUS
"
-ne
0
]
;
then
# Then check if the service is running. If it is: don't start again.
# Program is running, exit with error code 1.
if
[
"
$web_status
"
=
"0"
]
;
then
echo
"Error!
$DESC
$NAME
is currently running!"
echo
"The Unicorn web server already running with pid
$wpid
, not restarting."
exit
1
else
else
if
[
`
whoami
`
=
root
]
;
then
echo
"Starting the GitLab Unicorn web server..."
execute
"rm -f
$SOCKET_PATH
/gitlab.socket"
# Remove old socket if it exists
execute
"RAILS_ENV=production bundle exec unicorn_rails
$DAEMON_OPTS
> /dev/null 2>&1 &"
rm
-f
"
$socket_path
"
/gitlab.socket
execute
"mkdir -p
$PID_PATH
&&
$START_SIDEKIQ
> /dev/null 2>&1 &"
# Start the webserver
echo
"
$DESC
started
"
bundle
exec
unicorn_rails
-D
-c
"
$unicorn_conf
"
-E
"
$RAILS_ENV
"
fi
fi
# If sidekiq is already running, don't start it again.
if
[
"
$sidekiq_status
"
=
"0"
]
;
then
echo
"The Sidekiq job dispatcher is already running with pid
$spid
, not restarting"
else
echo
"Starting the GitLab Sidekiq event dispatcher..."
RAILS_ENV
=
$RAILS_ENV
bundle
exec
rake sidekiq:start
# We are sleeping a bit here because sidekiq is slow at writing it's pid
sleep
2
fi
fi
# Finally check the status to tell wether or not GitLab is running
status
}
}
# Asks the Unicorn and the Sidekiq if they would be so kind as to stop, if not kills them.
stop
()
{
stop
()
{
cd
$APP_ROOT
check_not_running
check_pid
# If the Unicorn web server is running, tell it to stop;
if
[
"
$PID
"
-ne
0
-a
"
$STATUS
"
-ne
0
]
;
then
if
[
"
$web_status
"
=
"0"
]
;
then
## Program is running, stop it.
kill
-QUIT
"
$wpid
"
&
kill
-QUIT
`
cat
$WEB_SERVER_PID
`
echo
"Stopping the GitLab Unicorn web server..."
execute
"mkdir -p
$PID_PATH
&&
$STOP_SIDEKIQ
> /dev/null 2>&1 &"
stopping
=
true
rm
"
$WEB_SERVER_PID
"
>>
/dev/null
echo
"
$DESC
stopped"
else
else
## Program is not running, exit with error.
echo
"The Unicorn web was not running, doing nothing."
echo
"Error!
$DESC
not started!"
fi
exit
1
# And do the same thing for the Sidekiq.
if
[
"
$sidekiq_status
"
=
"0"
]
;
then
printf
"Stopping Sidekiq job dispatcher."
RAILS_ENV
=
$RAILS_ENV
bundle
exec
rake sidekiq:stop &
stopping
=
true
else
echo
"The Sidekiq was not running, must have run out of breath."
fi
fi
}
restart
()
{
cd
$APP_ROOT
# If something needs to be stopped, lets wait for it to stop. Never use SIGKILL in a script.
check_pid
while
[
"
$stopping
"
=
"true"
]
;
do
if
[
"
$PID
"
-ne
0
-a
"
$STATUS
"
-ne
0
]
;
then
sleep
1
echo
"Restarting
$DESC
..."
check_status
kill
-USR2
`
cat
$WEB_SERVER_PID
`
if
[
"
$web_status
"
=
"0"
-o
"
$sidekiq_status
"
=
"0"
]
;
then
execute
"mkdir -p
$PID_PATH
&&
$STOP_SIDEKIQ
> /dev/null 2>&1"
printf
"."
if
[
`
whoami
`
=
root
]
;
then
execute
"mkdir -p
$PID_PATH
&&
$START_SIDEKIQ
> /dev/null 2>&1 &"
fi
echo
"
$DESC
restarted."
else
else
echo
"Error,
$NAME
not running!
"
printf
"
\n
"
exit
1
break
fi
fi
done
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.
status
}
}
# Returns the status of GitLab and it's components
status
()
{
status
()
{
cd
$APP_ROOT
check_not_running
check_pid
if
[
"
$web_status
"
=
"0"
]
;
then
if
[
"
$PID
"
-ne
0
-a
"
$STATUS
"
-ne
0
]
;
then
echo
"The GitLab Unicorn webserver with pid
$wpid
is running."
echo
"
$DESC
/ Unicorn with PID
$PID
is running."
echo
"
$DESC
/ Sidekiq with PID
$SPID
is running."
else
else
echo
"
$DESC
is not running."
printf
"The GitLab Unicorn webserver is
\0
33[31mnot running
\0
33[0m.
\n
"
exit
1
fi
if
[
"
$sidekiq_status
"
=
"0"
]
;
then
echo
"The GitLab Sidekiq job dispatcher with pid
$spid
is running."
else
printf
"The GitLab Sidekiq job dispatcher is
\0
33[31mnot running
\0
33[0m.
\n
"
fi
if
[
"
$web_status
"
=
"0"
-a
"
$sidekiq_status
"
=
"0"
]
;
then
printf
"GitLab and all it's components are
\0
33[32mup and running
\0
33[0m.
\n
"
fi
fi
}
}
## Check to see if we are running as root first.
reload
(){
## Found at http://www.cyberciti.biz/tips/shell-root-user-check-script.html
check_not_running
if
[
"
$(
id
-u
)
"
!=
"0"
]
;
then
if
[
"
$wpid
"
=
"0"
]
;
then
echo
"Th
is script must be run as root
"
echo
"Th
e GitLab Unicorn Web server is not running thus it's configuration can't be reloaded.
"
exit
1
exit
1
fi
fi
printf
"Reloading GitLab configuration... "
kill
-HUP
"
$wpid
"
echo
"Done."
}
## Finally the input handling.
case
"
$1
"
in
case
"
$1
"
in
start
)
start
)
...
@@ -119,20 +216,19 @@ case "$1" in
...
@@ -119,20 +216,19 @@ case "$1" in
stop
stop
;;
;;
restart
)
restart
)
restart
stop
start
;;
;;
reload|force-reload
)
reload|force-reload
)
echo
-n
"Reloading
$NAME
configuration: "
reload
kill
-HUP
`
cat
$PID
`
echo
"done."
;;
;;
status
)
status
)
status
status
;;
;;
*
)
*
)
echo
"Usage: s
udo service gitlab {start|stop|restart|reload}"
>
&2
echo
"Usage: s
ervice gitlab {start|stop|restart|reload|status}"
exit
1
exit
1
;;
;;
esac
esac
exit
0
exit
\ No newline at end of file
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