Bitbucket Server を Linux サービスとして実行する
このページでは、Bitbucket Server を Linux サービスとして実行する方法を説明しています。これはアーカイブ ファイルから Bitbucket Server を手動でインストールまたはアップグレードする場合にのみ適用されます。詳細については、「Bitbucket Server をアーカイブ ファイルからインストールする」を参照してください。
Bitbucket Server は起動時に外部データベースが利用可能であることを前提としています。これらの方法ではサービスの依存関係がサポートされておらず、スタートアップ スクリプトは外部データベースが利用可能になるまで待機しません。
Linux サーバーでの本番使用の場合、Bitbucket Server は Linux サービス、つまりデーモン プロセスとして実行するように構成されている必要があります。これには以下のメリットがあります。
- オペレーティング システムの再起動時に Bitbucket Server を自動的に再起動できます。
- 何らかの理由で停止した際に Bitbucket Server を自動的に再起動できます。
- Bitbucket Server を誤ってシャットダウンする可能性が低くなります (Bitbucket Server を手動で起動した場合、ターミナルを閉じるとシャットダウンされるため)。
- Bitbucket Server JVM からのログをサービスによって適切に管理できます。
アトラシアンではシステム管理タスクをサポートしていません。これらの手順はガイドとしてのみ提供されており、ご使用のオペレーティング システムの最新版に対応していない可能性があります。
Java Service Wrapper の使用
Java Service Wrapper を使用することで Bitbucket Server を Linux 上のサービスとして実行できます。Service Wrapper は Debian、Ubuntu、Red Hat で動作することが確認されています。
Service Wrapper には以下のメリットがあります。
- Java アプリケーションである Bitbucket Server をサービスとして実行できます。
- ユーザーが常にシステムにログオンしたり、Bitbucket Server を実行するためにデスクトップで常にコマンド プロンプトを開いて実行したりする必要がありません。
- 利便性、システム パフォーマンス、セキュリティ向上のため、バックグラウンドでサービスとして Bitbucket Server を実行できます。
- Bitbucket Server がシステムの起動時に自動的に起動され、ユーザーのログインを必要としません。
- Bitbucket Server の開始、停止、設定変更などの、Bitbucket Server への直接的な操作は、管理者のみが行えます。
- 高度なフェイルオーバー、エラー リカバリ、分析機能を提供し、Bitbucket Server のアップタイムを最大化できます。
Wrapper のインストールと構成の手順については、http://wrapper.tanukisoftware.com/doc/english/launch-nix.html を参照してください。
The service wrapper supports the standard commands for SysV init scripts, so it should work if you just create a symlink to it from /etc/init.d
.
init.d スクリプトの使用
Linux でシステムの再起動時にプロセスを再起動するようにするための標準的な方法は、init.d スクリプトを使用することです。この方法では、Bitbucket Server が停止した場合に Bitbucket Server が再起動されません。
- Bitbucket Server を停止します。
bitbucket ユーザーを作成し、そのユーザーに権限を設定して、Bitbucket Server のホーム ディレクトリを作成し、アップグレードを簡単にするためのシンボリックリンクを作成します。
$> curl -OL https://www.atlassian.com/software/stash/downloads/binary/atlassian-bitbucket-X.Y.Z.tar.gz $> tar xz -C /opt -f atlassian-bitbucket-X.Y.Z.tar.gz $> ln -s /opt/atlassian-bitbucket-X.Y.Z /opt/atlassian-bitbucket-latest # Create a home directory $> mkdir /opt/bitbucket-home # ! Update permissions and ownership accordingly
(上記のコマンドの X.Y.Z は Bitbucket Server のバージョン番号で置き換えてください)
Create the startup script in
/etc/init.d/bitbucket
with the following contents (Ensure the script is executable by runningchmod 755 bitbucket
):#! /bin/sh ### BEGIN INIT INFO # Provides: bitbucket # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Initscript for Atlassian Bitbucket Server # Description: Automatically start Atlassian Bitbucket Server when the system starts up. # Provide commands for manually starting and stopping Bitbucket Server. ### END INIT INFO # Adapt the following lines to your configuration # RUNUSER: The user to run Bitbucket Server as. RUNUSER=vagrant # BITBUCKET_INSTALLDIR: The path to the Bitbucket Server installation directory BITBUCKET_INSTALLDIR="/opt/atlassian-bitbucket-X.Y.Z" # BITBUCKET_HOME: Path to the Bitbucket home directory BITBUCKET_HOME="/opt/bitbucket-home" # ================================================================================== # ================================================================================== # ================================================================================== # PATH should only include /usr/* if it runs after the mountnfs.sh script PATH=/sbin:/usr/sbin:/bin:/usr/bin DESC="Atlassian Bitbucket Server" NAME=bitbucket PIDFILE=$BITBUCKET_HOME/log/bitbucket.pid SCRIPTNAME=/etc/init.d/$NAME # Read configuration variable file if it is present [ -r /etc/default/$NAME ] && . /etc/default/$NAME # Define LSB log_* functions. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. . /lib/lsb/init-functions run_with_home() { if [ "$RUNUSER" != "$USER" ]; then su - "$RUNUSER" -c "export BITBUCKET_HOME=${BITBUCKET_HOME};${BITBUCKET_INSTALLDIR}/bin/$1" else export BITBUCKET_HOME=${BITBUCKET_HOME};${BITBUCKET_INSTALLDIR}/bin/$1 fi } # # Function that starts the daemon/service # do_start() { run_with_home start-bitbucket.sh } # # Function that stops the daemon/service # do_stop() { if [ -e $PIDFILE ]; then run_with_home stop-bitbucket.sh else log_failure_msg "$NAME is not running." fi } case "$1" in start) [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" do_start case "$?" in 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; esac ;; stop) [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" do_stop case "$?" in 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; esac ;; status) if [ ! -e $PIDFILE ]; then log_failure_msg "$NAME is not running." return 1 fi status_of_proc -p $PIDFILE "" $NAME && exit 0 || exit $? ;; restart|force-reload) # # If the "reload" option is implemented then remove the # 'force-reload' alias # log_daemon_msg "Restarting $DESC" "$NAME" do_stop case "$?" in 0|1) do_start case "$?" in 0) log_end_msg 0 ;; 1) log_end_msg 1 ;; # Old process is still running *) log_end_msg 1 ;; # Failed to start esac ;; *) # Failed to stop log_end_msg 1 ;; esac ;; *) echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 exit 3 ;; esac
システム ブートで実行する
システム ブートで開始するには、スタートアップ プロセスにスクリプトを追加します。
Ubuntu (およびその他の Debian 派生製品) の場合:update-rc.d bitbucket defaults
RHEL (およびその他の派生製品) の場合:chkconfig --add bitbucket --level 0356
Note: You may have to install the
redhat-lsb
package on RHEL (or derivatives) to provide the LSB functions used in the script.コンピューターを再起動し、Bitbucket Server サービスが復旧されることを確認します。
systemd unit ファイルの使用
この方法は Patrick Nelson が Fedora システム用にセットアップしたアプローチです。この方法は、システムの初期化に systemd を使用する他のディストリビューションでも機能します。この方法では、Bitbucket Server が停止した場合に Bitbucket Server が再起動されません。
Create a
bitbucket.service
file in your/etc/systemd/system/
directory with the following lines:[Unit] Description=Atlassian Bitbucket Server Service After=syslog.target network.target [Service] Type=forking User=atlbitbucket ExecStart=/opt/atlassian-bitbucket-X.Y.Z/bin/start-bitbucket.sh ExecStop=/opt/atlassian-bitbucket-X.Y.Z/bin/stop-bitbucket.sh [Install] WantedBy=multi-user.target
The value forUser
should be adjusted to match the user that Bitbucket Server runs as.ExecStart
andExecStop
should be adjusted to match the path to your<Bitbucket Server installation directory>
.ターミナルで次のコマンドを実行し、起動時のサービス開始を有効にします。
systemctl enable bitbucket.service
- Bitbucket Server を停止してからシステムを再起動し、Bitbucket Server が意図したように開始することを確認します。
- 次のコマンドを使用してサービスを管理します。
サービスの無効化
systemctl disable bitbucket.service
起動時にサービスが開始するように設定されていることの確認
if [ -f /etc/systemd/system/*.wants/bitbucket.service ]; then echo "On"; else echo "Off"; fi
サービスを手動で開始および停止
systemctl start bitbucket systemctl stop bitbucket
Bitbucket Server のステータスの確認
systemctl status bitbucket