--- gitlab.orig 2016-08-06 05:00:56.782535000 +0200 +++ gitlab 2016-08-06 06:46:54.637809000 +0200 @@ -2,17 +2,6 @@ # $FreeBSD: head/www/gitlab/files/gitlab.in 417194 2016-06-21 08:36:56Z tz $ -### 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 @@ -51,30 +40,36 @@ 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 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 http://127.0.0.1:8080 -authSocket $rails_socket -documentRoot $app_root/public" +gitlab_workhorse_options="-listenNetwork unix -listenAddr $workhorse_socket -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 +# 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 +# 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 +# if ! cd "$app_root" ; then +# echo "Failed to cd into $app_root, exiting!"; exit 1 +# fi + +if ! su - $app_user -c "echo \$RAILS_ENV" >/dev/null +then + echo "ERROR: RAILS_ENV not set for user $app_user, login.conf(5)" + exit 80 fi - ### Init Script functions ## Gets the pids from the files @@ -218,34 +213,26 @@ 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 ${app_user} ${app_root}/bin/web start + # 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 - RAILS_ENV=$RAILS_ENV bin/background_jobs start & + echo "Starting GitLab Sidekiq" + su - $app_user -c "${app_root}/bin/background_jobs start" fi if [ "$gitlab_workhorse_status" = "0" ]; then @@ -254,10 +241,11 @@ # 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 ${app_user} \ + $gitlab_workhorse_dir/gitlab-workhorse $gitlab_workhorse_options \ + >> $gitlab_workhorse_log 2>&1 fi if [ "$mail_room_enabled" = true ]; then @@ -265,7 +253,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" + /usr/sbin/daemon -u ${app_user} ${app_root}/bin/mail_room start fi fi @@ -281,19 +270,21 @@ if [ "$web_status" = "0" ]; then echo "Shutting down GitLab Unicorn" - RAILS_ENV=$RAILS_ENV bin/web stop + su - $app_user -c "${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 - $app_user -c "${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 - $app_user -c "${rails_root}/bin/mail_room stop" fi # If something needs to be stopped, lets wait for it to stop. Never use SIGKILL in a script. @@ -361,15 +352,15 @@ exit 1 fi printf "Reloading GitLab Unicorn configuration... " - RAILS_ENV=$RAILS_ENV bin/web reload + $sudo env 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 + $sudo env 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 + $sudo env RAILS_ENV=$RAILS_ENV bin/mail_room restart fi wait_for_pids @@ -386,29 +377,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"