When using the root user, Search server cannot be started due to "don't run <search server> as root"
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
The Bitbucket cannot connect to the search server because the search server fails to start. The error occurs when attempting to run ElasticSearch/OpenSearch as the root user.
Environment
- Any Bitbucket version, using bundled Search
- Linux
Diagnosis
When attempting to start Bitbucket using the start-bitbucket.sh
script as root, the following error message appears in the console output :
root@myserver:# cd /opt/atlassian/bitbucket/bin/
root@myserver:/opt/atlassian/bitbucket/bin# sh start-search.sh
Starting Elasticsearch bundled with Atlassian Bitbucket
BITBUCKET_HOME set to /var/atlassian/application-data/bitbucket
-e Starting Elasticsearch bundled with Atlassian Bitbucket as current user
-e
Elasticsearch bundled with Atlassian Bitbucket started successfully
root@myserver:/opt/atlassian/bitbucket/bin# Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root.
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:93)
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:144)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:270)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
Refer to the log for complete error details.
The error can also be found in the atlassian-bitbucket-search.log:
[2024-11-26T07:27:20,712][ERROR][o.o.b.Bootstrap ] [bitbucket_bundled] Exception
java.lang.RuntimeException: can not run opensearch as root
at org.opensearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:124) ~[opensearch-1.3.19.jar:1.3.19]
at org.opensearch.bootstrap.Bootstrap.setup(Bootstrap.java:191) ~[opensearch-1.3.19.jar:1.3.19]
at org.opensearch.bootstrap.Bootstrap.init(Bootstrap.java:412) [opensearch-1.3.19.jar:1.3.19]
at org.opensearch.bootstrap.OpenSearch.init(OpenSearch.java:178) [opensearch-1.3.19.jar:1.3.19]
at org.opensearch.bootstrap.OpenSearch.execute(OpenSearch.java:169) [opensearch-1.3.19.jar:1.3.19]
at org.opensearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:100) [opensearch-1.3.19.jar:1.3.19]
at org.opensearch.cli.Command.mainWithoutErrorHandling(Command.java:138) [opensearch-cli-1.3.19.jar:1.3.19]
at org.opensearch.cli.Command.main(Command.java:101) [opensearch-cli-1.3.19.jar:1.3.19]
at org.opensearch.bootstrap.OpenSearch.main(OpenSearch.java:135) [opensearch-1.3.19.jar:1.3.19]
at org.opensearch.bootstrap.OpenSearch.main(OpenSearch.java:101) [opensearch-1.3.19.jar:1.3.19]
[2024-11-26T07:27:20,717][ERROR][o.o.b.OpenSearchUncaughtExceptionHandler] [bitbucket_bundled] uncaught exception in thread [main]
org.opensearch.bootstrap.StartupException: java.lang.RuntimeException: can not run opensearch as root
at org.opensearch.bootstrap.OpenSearch.init(OpenSearch.java:182) ~[opensearch-1.3.19.jar:1.3.19]
at org.opensearch.bootstrap.OpenSearch.execute(OpenSearch.java:169) ~[opensearch-1.3.19.jar:1.3.19]
at org.opensearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:100) ~[opensearch-1.3.19.jar:1.3.19]
at org.opensearch.cli.Command.mainWithoutErrorHandling(Command.java:138) ~[opensearch-cli-1.3.19.jar:1.3.19]
at org.opensearch.cli.Command.main(Command.java:101) ~[opensearch-cli-1.3.19.jar:1.3.19]
at org.opensearch.bootstrap.OpenSearch.main(OpenSearch.java:135) ~[opensearch-1.3.19.jar:1.3.19]
at org.opensearch.bootstrap.OpenSearch.main(OpenSearch.java:101) ~[opensearch-1.3.19.jar:1.3.19]
Caused by: java.lang.RuntimeException: can not run opensearch as root
at org.opensearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:124) ~[opensearch-1.3.19.jar:1.3.19]
at org.opensearch.bootstrap.Bootstrap.setup(Bootstrap.java:191) ~[opensearch-1.3.19.jar:1.3.19]
at org.opensearch.bootstrap.Bootstrap.init(Bootstrap.java:412) ~[opensearch-1.3.19.jar:1.3.19]
at org.opensearch.bootstrap.OpenSearch.init(OpenSearch.java:178) ~[opensearch-1.3.19.jar:1.3.19]
... 6 more
Cause
The root cause of this issue is that ElasticSearch and OpenSearch includes a validation step during startup that prevents it from running as the root user for security reasons.
Solution
To resolve this issue, ensure that Bitbucket is not run as the root user.
When starting Bitbucket manually, follow these steps:
- Login as a dedicated Bitbucket user. The default is
atlbitbucket,
but verify the correct user for your system. - Start Bitbucket using this dedicated user account.
If running Bitbucket as a service:
- Follow the guidelines from Run Bitbucket as a Linux service