Trying to start sonarqube but getting this error as Removed stale pid file: ./SonarQube.pid

I have installed latest version of sonarqube and given full permissions with user sonar.
but while trying to start sonar server getting error as " Removed stale pid file: ./SonarQube.pid."
i have checked in logs no issue found in that.
can someone help me in this .

thanks in advance

Hey there.

That’s not an error – just a fact of what has been done!

Are there really no log messages in any of your SonarQube installation folder’s /logs/ directory? See the documentation on Checking the logs.

thanks for replying and i have gone through your suggestions i didnot see any error in the logs
for your reference i am pasting the logs here

[root@sonarqube logs]# cat sonar.log
2023.04.10 08:09:28 INFO app[o.s.a.AppFileSystem] Cleaning or creating temp directory /opt/sonar/temp
2023.04.10 08:09:28 INFO app[o.s.a.es.EsSettings] Elasticsearch listening on [HTTP: 127.0.0.1:9001, TCP: 127.0.0.1:45691]
2023.04.10 08:09:28 INFO app[o.s.a.ProcessLauncherImpl] Launch process[ELASTICSEARCH] from [/opt/sonar/elasticsearch]: /opt/sonar/elasticsearch/bin/elasticsearch
2023.04.10 08:09:28 INFO app[o.s.a.SchedulerImpl] Waiting for Elasticsearch to be up and running
2023.04.10 08:09:31 WARN app[o.s.a.p.AbstractManagedProcess] Process exited with exit value [ElasticSearch]: 1
2023.04.10 08:09:31 INFO app[o.s.a.SchedulerImpl] Process[ElasticSearch] is stopped
2023.04.10 08:09:31 INFO app[o.s.a.SchedulerImpl] SonarQube is stopped

There should be something in the es.log file.

please find the below es logs

    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:77) ~[elasticsearch-7.17.8.jar:7.17.8]
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:112) ~[elasticsearch-cli-7.17.8.jar:7.17.8]
    at org.elasticsearch.cli.Command.main(Command.java:77) ~[elasticsearch-cli-7.17.8.jar:7.17.8]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:125) ~[elasticsearch-7.17.8.jar:7.17.8]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:80) ~[elasticsearch-7.17.8.jar:7.17.8]

Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:107) ~[elasticsearch-7.17.8.jar:7.17.8]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:183) ~[elasticsearch-7.17.8.jar:7.17.8]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:434) ~[elasticsearch-7.17.8.jar:7.17.8]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:169) ~[elasticsearch-7.17.8.jar:7.17.8]

java.lang.RuntimeException: can not run elasticsearch as root

There’s your issue! You can’t start as a root user (no sudo /.sonar.sh start, for example).

I have created a sonar user and given the permissions and with sonar user am trying to run sonarqube but still it is failing. The same error am getting

What command are you running to start the server? You might also want to try running whoami immediately before running that command.

[sonar@sonarqube linux-x86-64]$ ls
sonar.sh
[sonar@sonarqube linux-x86-64]$ ./sonar.sh start
/usr/bin/java
Starting SonarQube…
./sonar.sh: line 161: …/…/logs/nohup.log: Permission denied
Removed stale pid file: ./SonarQube.pid
Failed to start SonarQube.
[sonar@sonarqube linux-x86-64]$ whoami
sonar
[sonar@sonarqube linux-x86-64]$

That seems like a different issue than before.

Caused by: java.lang.RuntimeException: can not run elasticsearch as root

Are you still facing this issue, or do you only receive the ./sonar.sh: line 161: …/…/logs/nohup.log: Permission denied issue now?

Now it is showing as permission denied and also as removed pid file. Dont no what’s happening exactly am unable to solve the error.

If you have created a new user, you probably need to give permissions to that user recursively in the SonarQube install directly (think chown -R)

I have given the permissions recurresively.still unable to start, after that i posted it on community for assistance

And you’re receiving the same error as before?

./sonar.sh: line 161: …/…/logs/nohup.log: Permission denied

It’s really important that you are detailed in your responses – the commands you run, the logs you get… We cannot make guesses.

So what would you Suggest me to solve this issue

I’m getting the same error, please find below.

[sonar@ip-172-31-45-225 linux-x86-64]$ ./sonar.sh start
/usr/bin/java
Starting SonarQube…
Removed stale pid file: ./SonarQube.pid
Started SonarQube.
[sonar@ip-172-31-45-225 linux-x86-64]$ ./sonar.sh status
/usr/bin/java
SonarQube is running (2241).

Also, its keep on going into “Not Running status” even though we start it. I’ve added sonar user into sudoers file. changed the owner form root to sonar and files permissions to Recursive.

➜ linux-x86-64 sudo ./sonar.sh start
/usr/bin/java
Starting SonarQube…
Started SonarQube.
➜ linux-x86-64 sudo ./sonar.sh status
/usr/bin/java
Removed stale pid file: ./SonarQube.pid
SonarQube is not running.

I am getting the same error trying to go with sonar user. The details are below:

[root@ip-172-31-59-163 ~]# su - sonar
Last login: Sun Sep 3 06:21:25 UTC 2023 on pts/0
Last failed login: Sun Sep 3 06:26:28 UTC 2023 on pts/0
There was 1 failed login attempt since the last successful login.
[sonar@ip-172-31-59-163 ~]$ whoami
sonar
[sonar@ip-172-31-59-163 ~]$ pwd
/home/sonar
[sonar@ip-172-31-59-163 ~]$ cd /opt/sonarqube/bin/linux-x86-64/
[sonar@ip-172-31-59-163 linux-x86-64]$ ls -lrt
total 8
-rwxrwxr-x. 1 sonar sonar 7133 Aug 29 2022 sonar.sh
[sonar@ip-172-31-59-163 linux-x86-64]$ sh sonar.sh start
/usr/bin/java
Starting SonarQube…
Started SonarQube.
[sonar@ip-172-31-59-163 linux-x86-64]$ sh sonar.sh status
/usr/bin/java
Removed stale pid file: ./SonarQube.pid
SonarQube is not running.

Please help out if anyone fixed it

1 Like

Open the SonarQube configuration file
sudo nano /opt/sonarqube/conf/sonar.properties
find the following lines :
#sonar.jdbc.username=
#sonar.jdbc.password=

change it as

sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:postgresql://localhost:5432/sonarqube

then save that file
Edit the sonar script file and set RUN_AS_USER
sudo nano /opt/sonarqube/bin/linux-x86-64/sonar.sh
RUN_AS_USER=sonar
then save that file and
now switch to — sudo su sonar
then move to cd /opt/sonarqube/bin/linux-x86-64/
./sonar.sh start
./sonar.sh status