this construct within a Systemd service unit isn't working:
ExecStartPre = /usr/bin/bash -c "systemctl set-environment BOSH_EXPORTER_BOSH_PASSWORD=$$(echo $$BOSH_CLIENT_SECRET)"
After the service unit is launched, no variable BOSH_EXPORTER_BOSH_PASSWORD variable could be found in the environment like expected:
$ sudo systemctl daemon-reload
$ sudo systemctl start bosh-exporter
$ sudo systemctl show-environment
LANG=en_US.UTF-8
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
$
The env variable BOSH_CLIENT_SECRET is set.
Thanks for pointers.
Related
I have a simple bash script as follows:
#!/bin/bash
gunicorn --bind 0.0.0.0:5000 --chdir server/ run:app -w 2
supervisord -c /usr/src/server/supervisord.conf -n
The script is supposed to launch the gunicorn service and then start supervisor. However when the script is called, only the gunciron service is started and not the supervisor service.
The script is being called as follows from a Dockerfile:
FROM python:3.8.1
RUN apt-get update && \
apt-get -y install netcat && \
apt-get clean
RUN apt-get install -y libpq-dev
RUN apt-get install -y redis-server
COPY . usr/src/server
WORKDIR /usr/src
RUN pip install -r server/requirements.txt
RUN chmod +x /usr/src/server/start.sh
CMD ["/usr/src/server/start.sh"]
I have tried using the && separator between the 2 commands as well, but that doesn't seem to make a difference.
The bash script will move on to the next command when the first command has finished running. supervisord will start when gunicorn exits.
To run Gunicorn in the background, pass the --daemon option.
#!/bin/bash
gunicorn --bind 0.0.0.0:5000 --chdir server/ run:app -w 2 --daemon
supervisord -c /usr/src/server/supervisord.conf -n
However, this doesn't make much sense to me. Since you're running Supervisor, why aren't you running Gunicorn from Supervisor? Starting daemons is Supervisor's job.
I am new to shell scripting, Recently started with basic. I have written code to check if i have cassandra nodes and it gives me yes or no if no then do execute some command. My problem is i already have started node1 and i am checking if node is already there then get the id of that container and start that container. But when i run it, it gets the id of the container and takes so long and never starts. If i start the container without shell commands it starts. But i want to indulge them in shell.
This is my code:
if sudo docker ps -a | grep -q 'node1';then
sudo docker inspect --format="{{.Id}}" node1
read num
sudo docker start num
elif sudo docker ps -a | grep -q 'node2';then
sudo docker inspect --formar="{{.Id}}" node2
read Idnode2
sudo docker start Idnode2
else
sudo docker run --name node1 -d -e CASSANDRA_BROADCAST_ADDRESS=192.168.1.xx -p 7000:7000 cassandra:2
fi
output:
./tet.sh
f1713abbee52ca465962ec53e97dde62058d37859005f77786db3e3eebe0086c
blinks forever after this
I am not getting why its blinking and not executing.
I solved it myself by using this command below
if sudo docker ps -a | grep -q 'node1';then
sudo docker inspect --format="{{.Id}}" node1
sudo docker start node1
elif sudo docker ps -a | grep -q 'node2';then
sudo docker inspect --formar="{{.Id}}" node2
read Idnode2
sudo docker start Idnode2
else
sudo docker run --name node1 -d -e CASSANDRA_BROADCAST_ADDRESS=192.168.1.xx -p 7000:7000 cassandra:2
fi
I try to run command as other user in Ubuntu. But it cannot find the command.
$ sudo su - hbase -c "echo $JAVA_HOME"
/usr/local/jdk
$ sudo su - hbase -c "echo $PATH"
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/jdk/bin
$ sudo su - hbase -c "java -version"
-su: java: command not found
$ sudo su - hbase -c "/usr/local/jdk/bin/java -version"
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
I tested in centos, there is no problem. I don't know why? And how can I run java in other user?
My JAVA_HOME is set in /etc/bash.bashrc, and Ubuntu version is ubuntu server 14.04.1.
Actually, I'm trying to start/stop hbase in hadoop user in
$ sudo su - hbase -c "/usr/local/hbase-1.1.5/bin/hbase-daemon.sh stop regionserver"
no regionserver to stop because no pid file /tmp/hbase-hbase-regionserver.pid
And this error is because it cannot get my environment export HBASE_PID_DIR="/data/hadoop/run/hbase", which I set in /etc/bash.bashrc.
I did more tests, first, I added export ENVTEST=hello to /etc/bash.bashrc, then, did the following tests.
$ echo $ENVTEST
$ sudo su - hbase -c "echo $ENVTEST"
$ source /etc/bash.bashrc
$ sudo su - hbase -c "echo $ENVTEST"
hello
It seems like, when you do sudo su - hbase -c "echo $ENVTEST", it is using the my user environment instead of hbase.
it looks like /usr/local/jdk/bin is not in hbase's PATH. add /usr/local/jdk/bin to PATH in /etc/bash.bashrc or /home/hbase/.bashrc.
because of the double-quotes, this test doesn't do what you might think:
sudo su - hbase -c "echo $PATH"
$PATH inside the double-quotes has its value substituted in before sudo su - hbase -c runs.
try these tests out:
sudo su - hbase -c "echo `whoami`"
sudo su - hbase -c 'echo `whoami`'
sudo su - hbase -c 'echo $JAVA_HOME'
sudo su - hbase -c 'echo $PATH'
I have a AWS Elastic beanstalk app with ruby/puma configured. I see this in the instance's /etc/init. A puma.conf file with
$ cat /etc/init/puma.conf
description "Elastic Beanstalk Puma Upstart Manager"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
script
exec /bin/bash <<"EOF"
EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir)
EB_SUPPORT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k support_dir)
. $EB_SUPPORT_DIR/envvars
. $EB_SCRIPT_DIR/use-app-ruby.sh
if grep -eq 'true' /etc/elasticbeanstalk/has_puma.txt; then
exec su -s /bin/bash -c "bundle exec puma -C $EB_SUPPORT_DIR/conf/pumaconf.rb" webapp
else
exec su -s /bin/bash -c "puma -C $EB_SUPPORT_DIR/conf/pumaconf.rb" webapp
fi
EOF
end script
Is it just me or is this broken? Running the if condition(grep -eq 'true' /etc/elasticbeanstalk/has_puma.txt;) in the terminal throws an error. As does just running the entire if block. /etc/elasticbeanstalk/has_puma.txt contains one word true.
We discovered this because we were facing subtle app level issues which went away when we used bundle exec.
I was able to fix that by modifying the puma.conf thus,
$ cat /etc/init/puma.conf
description "Elastic Beanstalk Puma Upstart Manager"
EB_SUPPORT_DIR=/opt/elasticbeanstalk/support
start on runlevel [2345]
stop on runlevel [!2345]
respawn
script
exec /bin/bash <<"EOF"
EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir)
EB_SUPPORT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k support_dir)
. $EB_SUPPORT_DIR/envvars
. $EB_SCRIPT_DIR/use-app-ruby.sh
exec su -s /bin/bash -c "cd /var/app/current && bundle exec puma -C $EB_SUPPORT_DIR/conf/pumaconf.rb" webapp
EOF
end script
I had to add the cd for it to work.. not too sure about it.
So is this a bug with the elastic beanstalk system? Is this fix correct or is there a cleaner/better way to achieve this?
I found very strange behaviour when I build and run docker container. I would like to have container with cassandra and ssh.
In my Dockerfile I've got:
RUN echo "deb http://www.apache.org/dist/cassandra/debian 20x main" | sudo tee -a /etc/apt/sources.list
RUN echo "deb-src http://www.apache.org/dist/cassandra/debian 20x main" | sudo tee -a /etc/apt/sources.list
RUN gpg --keyserver pgp.mit.edu --recv-keys 4BD736A82B5C1B00
RUN apt-key add ~/.gnupg/pubring.gpg
RUN apt-get update
RUN apt-get -y install cassandra
And then for ssh
RUN apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo '{{ docker_ssh_user }}:{{docker_ssh_password}}' | chpasswd
EXPOSE 22
And I added start script to run everything I want:
USER root
ADD start start
RUN chmod 777 start
CMD ["sh" ,"start"]
And here comes problem. When I have start like this below:
#!/bin/bash
/usr/sbin/sshd -D
/usr/sbin/cassandra -f
SSH is working well. I can do ssh root#172.17.0.x. After I log in container I try to run cqlsh to ensure that cassandra is working. But cassandra is not started for some reason and I can't access cqlsh. I've also checked /var/log/cassandra/ but it was empty.
In second scenario I change my start script to this:
#!/bin/bash
/usr/sbin/sshd -D & /usr/sbin/cassandra/ -f
And I again try to connect ssh root#172.17.0.x and then when I run cqlsh inside container I have connection to cqlsh.
So I was thinking that ampersand & is doing some voodoo that all works well ?
Why I can't run bash staring script with one command below another?
Or I'm missing something else??
Thanks for reading && helping.
Thanks to my friend linux guru we found the reason of error.
/usr/sbin/sshd -D means that -D : When this option is specified, sshd will not detach and does not become a deamon. This allows easy monitoring of sshd
So in the first script sshd -D was blocking next command to run.
In second script I've got & which let sshd -D go background and then cassandra could start.
Finally I've got this version of script:
#!/bin/bash
/usr/sbin/sshd
/usr/sbin/cassandra -f