Unable to run sonar.sh file in aws ec2 as non root user (sonar) using terraform

  • Trying to install SonarQube 8.4 in AWS ec2 from Terraform as userdata

  • Every part of the Terraform script are getting executed well , except the below lines. Where it is executed as root user , instead of sonar
    sudo su - sonar
    cd /opt/sonarqube/bin/linux-x86-64/
    ./sonar.sh start

Error detail; found the below error in es.log
01 ERROR es[o.e.b.Bootstrap] Exception
java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103) ~[elasticsearch-6.8.4.jar:6.8.4]

Hi @udayakumaran ,

welcome to the community :wave:

try it like this:

sudo su -c '/opt/sonarqube/bin/linux-x86-64/sonar.sh start' sonar

the user has to exist of cause, but i guess it does from your sample

hope that helps