Index: Makefile =================================================================== --- Makefile (Revision 429253) +++ Makefile (Arbeitskopie) @@ -4,7 +4,7 @@ PORTNAME= gitlab PORTVERSION= 8.11.11 DISTVERSIONPREFIX= v -PORTREVISION= 6 +PORTREVISION= 7 CATEGORIES= www devel MAINTAINER= tz@FreeBSD.org Index: files/gitlab.in =================================================================== --- files/gitlab.in (Revision 429253) +++ files/gitlab.in (Arbeitskopie) @@ -2,17 +2,6 @@ # $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 @@ -28,30 +17,31 @@ . /etc/rc.subr -name=gitlab -rcvar=gitlab_enable -extra_commands=status - +name="gitlab" +rcvar="gitlab_enable" status_cmd="print_status" start_cmd="start_gitlab" stop_cmd="stop_gitlab" restart_cmd="restart_gitlab" +extra_commands="reload status" +reload_cmd="reload_gitlab" -gitlab_enable=${gitlab_enable:-"NO"} -gitlab_authBackend=${gitlab_authBackend:-"http://127.0.0.1:8080"} - load_rc_config $name -### Environment variables -RAILS_ENV="production" +: ${gitlab_enable:="NO"} +: ${gitlab_authBackend:"http://127.0.0.1:8080"} +: ${gitlab_user:="git"} +: ${gitlab_env:="production"} +run_env="env RAILS_ENV=$gitlab_env" + # 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_root="/usr/local/www/gitlab" pid_path="$app_root/tmp/pids" socket_path="$app_root/tmp/sockets" rails_socket="$socket_path/gitlab.socket" +workhorse_socket=$socket_path/gitlab-workhorse.socket web_server_pid_path="$pid_path/unicorn.pid" sidekiq_pid_path="$pid_path/sidekiq.pid" mail_room_enabled=false @@ -58,24 +48,9 @@ mail_room_pid_path="$pid_path/mail_room.pid" gitlab_workhorse_dir=$(cd $app_root/../gitlab-workhorse && pwd) gitlab_workhorse_pid_path="$pid_path/gitlab-workhorse.pid" -gitlab_workhorse_options="-listenUmask 0 -listenNetwork unix -listenAddr $socket_path/gitlab-workhorse.socket -authBackend $gitlab_authBackend -authSocket $rails_socket -documentRoot $app_root/public" +gitlab_workhorse_options="-listenNetwork unix -listenAddr $workhorse_socket -authBackend $gitlab_authBackend -authSocket $rails_socket -documentRoot $app_root/public" gitlab_workhorse_log="$app_root/log/gitlab-workhorse.log" -shell_path="/bin/bash" -# Read configuration variable file if it is present -test -f /etc/default/gitlab && . /etc/default/gitlab - -# Switch to the app_user if it is not he/she who is running the script. -if [ "$USER" != "$app_user" ]; then - eval su - "$app_user" -c $(echo \")$0 "$@"$(echo \"); exit; -fi - -# Switch to the gitlab path, exit on failure. -if ! cd "$app_root" ; then - echo "Failed to cd into $app_root, exiting!"; exit 1 -fi - - ### Init Script functions ## Gets the pids from the files @@ -219,27 +194,18 @@ start_gitlab() { check_stale_pids - if [ "$web_status" != "0" ]; then - echo "Starting GitLab Unicorn" - fi - if [ "$sidekiq_status" != "0" ]; then - echo "Starting GitLab Sidekiq" - fi - if [ "$gitlab_workhorse_status" != "0" ]; then - echo "Starting gitlab-workhorse" - fi - if [ "$mail_room_enabled" = true ] && [ "$mail_room_status" != "0" ]; then - echo "Starting GitLab MailRoom" - fi - # Then check if the service is running. If it is: don't start again. if [ "$web_status" = "0" ]; then echo "The Unicorn web server already running with pid $wpid, not restarting." else + echo "Starting GitLab Unicorn" # 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 + # unicorn may break the current process on freebsd during + # deamonizing (defunct exists until new master has prefilled + # caches) - therefore start itself is decoupled + /usr/sbin/daemon -u ${gitlab_user} $run_env ${app_root}/bin/web start + # fi # If sidekiq is already running, don't start it again. @@ -246,7 +212,8 @@ 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 & + echo "Starting GitLab Sidekiq" + su - $gitlab_user -c "$run_env ${app_root}/bin/background_jobs start" fi if [ "$gitlab_workhorse_status" = "0" ]; then @@ -255,10 +222,12 @@ # No need to remove a socket, gitlab-workhorse does this itself. # Because gitlab-workhorse has multiple executables we need to fix # the PATH. - $app_root/bin/daemon_with_pidfile $gitlab_workhorse_pid_path \ - /usr/bin/env PATH=$gitlab_workhorse_dir:$PATH \ - gitlab-workhorse $gitlab_workhorse_options \ - >> $gitlab_workhorse_log 2>&1 & + echo "Starting gitlab-workhorse" + cd ${gitlab_workhorse_dir} && + /usr/sbin/daemon -p $gitlab_workhorse_pid_path \ + -u $gitlab_user -t gitlab-workhorse $run_env \ + $gitlab_workhorse_dir/gitlab-workhorse $gitlab_workhorse_options \ + >> $gitlab_workhorse_log 2>&1 fi if [ "$mail_room_enabled" = true ]; then @@ -266,7 +235,8 @@ 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 & + echo "Starting GitLab MailRoom" + su - $gitlab_user -c "$run_env ${app_root}/bin/mail_room start" fi fi @@ -282,19 +252,21 @@ if [ "$web_status" = "0" ]; then echo "Shutting down GitLab Unicorn" - RAILS_ENV=$RAILS_ENV bin/web stop + su - $gitlab_user -c "$run_env ${app_root}/bin/web stop" + [ -S ${rails_socket} ] && rm -f ${rails_socket} fi if [ "$sidekiq_status" = "0" ]; then echo "Shutting down GitLab Sidekiq" - RAILS_ENV=$RAILS_ENV bin/background_jobs stop + su - $gitlab_user -c "$run_env ${app_root}/bin/background_jobs stop" fi if [ "$gitlab_workhorse_status" = "0" ]; then echo "Shutting down gitlab-workhorse" kill -- $(cat $gitlab_workhorse_pid_path) + [ -S ${workhorse_socket} ] && rm -f ${workhorse_socket} fi if [ "$mail_room_enabled" = true ] && [ "$mail_room_status" = "0" ]; then echo "Shutting down GitLab MailRoom" - RAILS_ENV=$RAILS_ENV bin/mail_room stop + su - $gitlab_user -c "$run_env ${app_root}/bin/mail_room stop" fi # If something needs to be stopped, lets wait for it to stop. Never use SIGKILL in a script. @@ -362,15 +334,15 @@ exit 1 fi printf "Reloading GitLab Unicorn configuration... " - RAILS_ENV=$RAILS_ENV bin/web reload + su - $gitlab_user -c "$run_env ${app_root}/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 + su - $gitlab_user -c "$run_env ${app_root}/bin/background_jobs restart" - if [ "$mail_room_enabled" != true ]; then + 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 + su - $gitlab_user -c "$run_env ${app_root}/bin/mail_room restart" fi wait_for_pids @@ -387,29 +359,5 @@ } -### 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"