--- files/gitlab.in (Revision 417361) +++ files/gitlab.in (Arbeitskopie) @@ -2,22 +2,11 @@ # $FreeBSD$ -### BEGIN INIT INFO -# Provides: gitlab -# Required-Start: $local_fs $remote_fs $network $syslog redis-server -# Required-Stop: $local_fs $remote_fs $network $syslog -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: GitLab git repository management -# Description: GitLab git repository management -# chkconfig: - 85 14 -### END INIT INFO - # Maintainer: Torsten Zuehlsdorff # Based on work of: @charlienewey, rovanion.luckey@gmail.com, @randx # PROVIDE: gitlab -# REQUIRE: LOGIN +# REQUIRE: redis nginx LOGIN # KEYWORD: shutdown # # Add the following line to /etc/rc.conf to enable GitLab: @@ -32,21 +21,25 @@ rcvar=gitlab_enable extra_commands=status -status_cmd="print_status" -start_cmd="start_gitlab" -stop_cmd="stop_gitlab" -restart_cmd="restart_gitlab" +: ${gitlab_user="git"} +: ${gitlab_railsenv="production"} +status_cmd="${name}_status" +start_cmd="${name}_start" +stop_cmd="${name}_stop" +#restart_cmd="${name}_restart" + +extra_commands="status reload" + gitlab_enable=${gitlab_enable:-"NO"} load_rc_config $name ### Environment variables -RAILS_ENV="production" # Script variable names should be lower-case not to conflict with # internal /bin/sh variables such as PATH, EDITOR or SHELL. -app_user="git" +app_user=${gitlab_user} app_root="/usr/local/www/gitlab" pid_path="$app_root/tmp/pids" socket_path="$app_root/tmp/sockets" @@ -215,7 +208,7 @@ } ## Starts Unicorn and Sidekiq if they're not running. -start_gitlab() { +gitlab_start() { check_stale_pids if [ "$web_status" != "0" ]; then @@ -238,7 +231,7 @@ # Remove old socket if it exists rm -f "$socket_path"/gitlab.socket 2>/dev/null # Start the web server - RAILS_ENV=$RAILS_ENV bin/web start + RAILS_ENV=$gitlab_railsenv bin/web start fi # If sidekiq is already running, don't start it again. @@ -245,7 +238,7 @@ if [ "$sidekiq_status" = "0" ]; then echo "The Sidekiq job dispatcher is already running with pid $spid, not restarting" else - RAILS_ENV=$RAILS_ENV bin/background_jobs start & + RAILS_ENV=$gitlab_railsenv bin/background_jobs start & fi if [ "$gitlab_workhorse_status" = "0" ]; then @@ -265,7 +258,7 @@ if [ "$mail_room_status" = "0" ]; then echo "The MailRoom email processor is already running with pid $mpid, not restarting" else - RAILS_ENV=$RAILS_ENV bin/mail_room start & + RAILS_ENV=$gitlab_railsenv bin/mail_room start & fi fi @@ -272,20 +265,20 @@ # Wait for the pids to be planted wait_for_pids # Finally check the status to tell wether or not GitLab is running - print_status + gitlab_status } ## Asks Unicorn, Sidekiq and MailRoom if they would be so kind as to stop, if not kills them. -stop_gitlab() { +gitlab_stop() { exit_if_not_running if [ "$web_status" = "0" ]; then echo "Shutting down GitLab Unicorn" - RAILS_ENV=$RAILS_ENV bin/web stop + RAILS_ENV=$gitlab_railsenv bin/web stop fi if [ "$sidekiq_status" = "0" ]; then echo "Shutting down GitLab Sidekiq" - RAILS_ENV=$RAILS_ENV bin/background_jobs stop + RAILS_ENV=$gitlab_railsenv bin/background_jobs stop fi if [ "$gitlab_workhorse_status" = "0" ]; then echo "Shutting down gitlab-workhorse" @@ -293,7 +286,7 @@ fi if [ "$mail_room_enabled" = true ] && [ "$mail_room_status" = "0" ]; then echo "Shutting down GitLab MailRoom" - RAILS_ENV=$RAILS_ENV bin/mail_room stop + RAILS_ENV=$gitlab_railsenv bin/mail_room stop fi # If something needs to be stopped, lets wait for it to stop. Never use SIGKILL in a script. @@ -316,11 +309,11 @@ rm "$mail_room_pid_path" 2>/dev/null fi - print_status + gitlab_status } ## Prints the status of GitLab and its components. -print_status() { +gitlab_status() { check_status if [ "$web_status" != "0" ] && [ "$sidekiq_status" != "0" ] && [ "$gitlab_workhorse_status" != "0" ] && { [ "$mail_room_enabled" != true ] || [ "$mail_room_status" != "0" ]; }; then echo "GitLab is not running." @@ -361,54 +354,28 @@ exit 1 fi printf "Reloading GitLab Unicorn configuration... " - RAILS_ENV=$RAILS_ENV bin/web reload + RAILS_ENV=$gitlab_railsenv 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 + RAILS_ENV=$gitlab_railsenv 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 + RAILS_ENV=$gitlab_railsenv bin/mail_room restart fi wait_for_pids - print_status + gitlab_status } ## Restarts Sidekiq and Unicorn. -restart_gitlab(){ +gitlab_restart(){ check_status if [ "$web_status" = "0" ] || [ "$sidekiq_status" = "0" ] || [ "$gitlab_workhorse" = "0" ] || { [ "$mail_room_enabled" = true ] && [ "$mail_room_status" = "0" ]; }; then - stop_gitlab + gitlab_stop fi - start_gitlab + gitlab_start } - -### Finally the input handling. - -case "$1" in - start) - start_gitlab - ;; - stop) - stop_gitlab - ;; - restart) - restart_gitlab - ;; - reload|force-reload) - reload_gitlab - ;; - status) - print_status - exit $gitlab_status - ;; - *) - echo "Usage: service gitlab {start|stop|restart|reload|status}" - exit 1 - ;; -esac - -exit +run_rc_command "$1"