Run Bitbucket as a Linux service
This page describes how to run Bitbucket Data Center and Server as a Linux service, and only applies if you are manually installing or upgrading Bitbucket from an archive file. See the page Install Bitbucket Server from an archive file for more details.
Bitbucket assumes that the external database is available when it starts; these approaches do not support service dependencies, and the startup scripts will not wait for the external database to become available.
For production use on a Linux server, Bitbucket should be configured to run as a Linux service, that is, as a daemon process. This has the following advantages:
- Bitbucket can be automatically restarted when the operating system restarts.
On this page:
- Bitbucket can be automatically restarted if it stops for some reason.
- Bitbucket is less likely to be accidentally shut down, as can happen if the terminal Bitbucket was manually started in is closed.
- Logs from the Bitbucket JVM can be properly managed by the service.
System administration tasks are not supported by Atlassian. These instructions are only provided as a guide and may not be up to date with the latest version of your operating system.
Using the Java Service Wrapper
Bitbucket can be run as a service on Linux using the Java Service Wrapper. The Service Wrapper is known to work with Debian, Ubuntu, and Red Hat.
The Service Wrapper provides the following benefits:
- Allows Bitbucket, which is a Java application, to be run as a service.
- No need for a user to be logged on to the system at all times, or for a command prompt to be open and running on the desktop to be able to run Bitbucket.
- The ability to run Bitbucket in the background as a service, for improved convenience, system performance and security.
- Bitbucket is launched automatically on system startup and does not require that a user be logged in.
- Users are not able to stop, start, or otherwise tamper with Bitbucket unless they are an administrator.
- Can provide advanced failover, error recovery, and analysis features to make sure that Bitbucket has the maximum possible uptime.
Please see http://wrapper.tanukisoftware.com/doc/english/launch-nix.html for wrapper installation and configuration instructions.
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.
Using an init.d script
The usual way on Linux to ensure that a process restarts at system restart is to use an init.d script. This approach does not restart Bitbucket if it stops by itself.
Create the startup script in
/etc/init.d/atlbitbucketwith the following contents (Ensure the script is executable by runningchmod 755 atlbitbucket):Enable the service to start at boot time:
For Ubuntu and other Debian derivatives, use:
update-rc.d atlbitbucket defaultsFor RHEL and derivatives, use:
chkconfig --add atlbitbucket --level 0356You may have to install the
redhat-lsbpackage on RHEL or derivatives to provide the LSB functions used in the script.
Gracefully shutdown Bitbucket.
Restart the machine to check that Bitbucket starts at boot time as expected.
Use the following commands to manage the service:
Disable the service (not to start at boot time):
# Ubuntu and other Debian derivatives update-rc.d atlbitbucket disable # RHEL and derivatives chkconfig atlbitbucket off --level 0356Check that the service is set to start at boot time:
# Ubuntu and other Debian derivatives ls /etc/rc*.d | grep atlbitbucket # RHEL and derivatives chkconfig --list | grep atlbitbucketManually start and stop the service:
service atlbitbucket start service atlbitbucket stopCheck the status of Bitbucket:
service atlbitbucket status
Using a systemd unit file
Thanks to Patrick Nelson for calling out this approach, which he set up for a Fedora system. It also works on other distributions that use systemd as the init system. This approach does not restart Bitbucket if it stops by itself.
Create the
atlbitbucket.servicefile 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 forUsershould be adjusted to match the user that Bitbucket runs as.ExecStartandExecStopshould be adjusted to match the path to your<Bitbucket installation directory>.Enable the service to start at boot time:
systemctl enable atlbitbucketGracefully shutdown Bitbucket.
Restart the machine to check that Bitbucket starts at boot time as expected.
- Use the following commands to manage the service:
Disable the service (not to start at boot time):
systemctl disable atlbitbucketCheck that the service is set to start at boot time:
systemctl is-enabled atlbitbucketManually start and stop the service:
systemctl start atlbitbucket systemctl stop atlbitbucketCheck the status of Bitbucket:
systemctl status atlbitbucket