Start sonar on debian 8 - installation

I have SonarQube 5.6.3 on a debian 8 VM and I want to start sonar with this command : sonar.sh start but it shows me this message : bash: sonar.sh: command not found. Can you tell me why it doesn't work?

For sonar.sh start to work, the current directory or . would have to be in your PATH. Try like this instead:
./sonar.sh start
This way Bash will know to execute the script in the current directory (hence the ./ prefix).
You might need to make the script executable first:
chmod +x sonar.sh

Related

Linux shell command source execute only with . call

On my ubuntu 18 server i create an .sh file like this one:
#!/bin/bash
source "/home/ubuntu/.venv36/bin/activate"
nohup python manage.py runserver &
well, i save it as startup.sh in my /var/www/web/core directory.
At this point if in console I put my working directory like this:
cd /var/www/web/core
and execute
. startup.sh
all work fine, virtualenv get created and nohup start runserver.
the problem is if from root i call directly my script like this:
/var/www/web/core/startup.sh
command source does not run, but nohup yes, and finnaly my app does not work.
How can I execute directly my sh file? I need to execute it at server startup, now I use in crontab the command:
#reboot /var/www/web/core/startup.sh
but it does not work like I explain above.

Run an shell script on startup (not login) on Ubuntu 14.04

I have a build server. I'm using the Azure Build Agent script. It's a shell script that will run continuously while the server is up. Problem is that I cannot seem to get it to run on startup. I've tried /etc/init.d and /etc/rc.local and the agent is not being run. Nothing concerning the build agent in the boot logs.
For /etc/init.d I created the script agent.sh which contains:
#!/bin/bash
sh ~/agent/run.sh
Gave it the proper permissions chmod 755 agent.shand moved it to /etc/init.d.
and for /etc/rc.local, I just appended the following
sh ~/agent/run.sh &
before exit 0.
What am I doing wrong?
EDIT: added examples.
EDIT 2: Just noticed that the init.d README says that shell scripts need to start with #!/bin/sh and not #!/bin/bash. Also used absolute path, but no change.
FINAL EDIT: As #ewrammer suggested, I used cron and it worked. crontab -e and then #reboot /home/user/agent/run.sh.
It is hard to see what is wrong if you are not posting what you have done, but why not add it as a cron job with #reboot as pattern? Then cron will run the script every time the computer starts.
Just in case, using a supervisor could be a good idea, In Ubuntu 14 you don't have systemd but you can choose from others https://en.wikipedia.org/wiki/Process_supervision.
If using immortal, after installing it, you just need to create a run.yml file in /etc/immortal with something like:
cmd: /path/to/command
log:
file: /var/log/command.log
This will start your script/command on every start, besides ensuring your script/app is always up and running.

Running Docker commands included in a shell script alongside other Linux commands and switching users

Using the Linux terminal, I run bash scripts (.sh files) containing sequences of commands I want to execute.
The issue is that I am unable to run a Docker command from within my shell script. I can run this Docker command when it's typed directly at the terminal with root privileges but not when I include it in the shell script file.
My script executed as a general user from command line, looks like this:
#!/usr/bin/env bash
cd /home/user/docker_backup
# remove /home/user/docker_backup/data
rm -rf data
# Switch to root privileges. my system is set to only run Docker as root
su
# Copy a folder from Docker container to host OS
docker cp <container-name>:/home/user/data /home/user/docker_backup
# More general user commands
cd ..
My code only runs until the su line above. After i enter the root password, nothing happens. if i type exit, i get permission errors, meaning the docker cp command failed.
**
This is my desired solution
**After thorough research, as I wanted to run my script as a general user, and only run certain commands as Root when necessary, I came up with a solution that works.
My script now looks like this (run with
$ sh script_name.sh):
#!/usr/bin/env bash
cd /home/user/docker_backup
# remove /home/user/docker_backup/data
rm -rf data
# Switch to root privileges. my system is set to only run Docker as root
su - root -c "docker cp <container-name>:/home/user/data /home/user/docker_backup"
# More general user commands
cd ..
Run shell script as general user. For commands that require root privileges, I use su - root -c "<command>". Terminal prompts for root password and executes command in quotes as root, then shell proceeds as general user.
Actually posting this as an answer:
You switch your current user to root during the script, but the script was executed by your own user.
So the docker cp command will also be executed as your own user, but you will be logged into the root account.
This results in you not seeing the output of docker cp (which might give you insight to not working - I think insufficient privilege).
A solution to this is either using sudo before docker cp, starting the script as root or adding your user to the group "docker", which authorizes your user to use the docker commands
I had the similar issue where the docker commands were running fine on the Terminal but the same commands were not running when I compiled them into a bash script and the issue was basically because of two reasons.
The docker commands need to be run with uplifted privileges that is with the sudo command ( Eg: sudo docker ps works but docker ps won't work). One could add the current user to docker group so that we need not use sudo with each docker command. Please visit this link and follow the section 2 to do the same.
Run the script in the correct way
One should have #! bin/bash at the starting of the script. It is a shebang that is required by each script.
One should save the file without .sh extension
One should provide the execution permission to the script by giving command chmod 777 script_name
run the script with bash script_name

Can't run startup.sh as startup despite being installed in PATH

I'm running Ubuntu 14.04. I've created a script called startup.sh and given it execute permissions. I put it in my $HOME/bin folder, and I've checked and this is indeed on the PATH. I've rebooted my computer just to be sure. I am still unable to run startup.sh just as a command (typing startup on the command line). Am I wrong in what I've done or assumed is possible?
My end goal was to be able to just type on the command line "startup" and execute the script I created.
$ startup
startup: command not found
$ echo $PATH
/home/travis/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
$ cd /home/travis/bin && ls -l
total 4
-rwxrwxr-x 1 travis travis 803 Dec 16 10:08 startup.sh
I can still run the script by navigating to $HOME/bin and running bash startup.sh of course, but that wasn't the goal.
Setting executable permissions and a #!/bin/bash line per How do I run a shell script without using "sh" or "bash" commands? did not work for me as an answer, hence my confusion.
If your file is named startup.sh, then the command to run it needs to be startup.sh.
If you want the command to be startup, don't include any extension on your filename: Just name it startup.

Stardog server start with license key : wrong STARDOG_HOME

I'm on MAC OSX. I added these lines in my ~/.bash_profile :
PATH="/usr/local/stardog/bin:${PATH}"
export STARDOG_HOME=/data/stardog
export PATH
Then, in command line, I execute
cp stardog-licence-key.bin $STARDOG_HOME as the quick-start documentation states.
But, this seems useless, because when I execute sudo stardog-admin server start, it says :
A Stardog license was not found.
The license file 'stardog-license-key.bin'
should be in your Stardog Home directory 'xx/xx'.
xx/xx is the current directory when I launch this command ... but stardog home directory is supposed to be /data/stardog, not my working directory !
How to tell stardog his actual home directory ?
Fine (and sorry), I did not mention some elements : I executed the command stardog-admin server start with sudo (as seen in the last edit of my question).
Reasons :
I launched this command with sudo because I needed some permissions to start stardog properly.
Problem : With sudo, stardog home is not the one defined in my previous .bash_profile anymore.
Solution : I give (owner) permissions to myself on the directory $STARDOG_HOME with the command sudo chown -R myUsername /data/stardog
Open a new bash, type stardog-admin server start without sudo, it works.

Resources