RabbitMQ Docker Bash Script Issue - .sh Not Found - bash

I am trying to create a RabbitMQ image that installs the rabbitmq_auth_backend_http plugin, and also executes a java application (.jar) via a bash script file. However, when I run the container I get this output from RabbitMQ:
/usr/local/bin/docker-deploy.sh: 2: /usr/local/bin/docker-deploy.sh:
: not found
Starting rabbit-sidecar application
Enabling plugins on node rabbit#039e6bd1bbfd:
bbitmq_auth_backend_http
The following plugins have been configured:
rabbitmq_auth_backend_http
rabbitmq_management
rabbitmq_management_agent
rabbitmq_web_dispatch
Applying plugin configuration to rabbit#039e6bd1bbfd...
The following plugins have been enabled:
rabbitmq_auth_backend_http
set 4 plugins.
Offline change; changes will take effect at broker restart.
/usr/local/bin/docker-deploy.sh: 4: /usr/local/bin/docker-deploy.sh: rabbitmq-server
: not found
It's also not finding rabbitmq-server which is needed to restart rabbit for the plugin to work.
To note, the java application appears to be working as it should and is just logging what it normally logs when its spun up as its own container.
Dockerfile
FROM rabbitmq:3.8.2-management
COPY ./rabbitmq.conf /etc/rabbitmq/rabbitmq.conf
RUN apt -y update && apt -y install openjdk-8-jdk
RUN mkdir /sidecar
ADD ./target/demo-0.0.1-SNAPSHOT.jar /sidecar/demo-0.0.1-SNAPSHOT.jar
ADD ./docker-deploy.sh /usr/local/bin/docker-deploy.sh
RUN chmod 755 /usr/local/bin/docker-deploy.sh #755
ENTRYPOINT ["sh", "/usr/local/bin/docker-deploy.sh"]
Script
#!/bin/bash
echo "Starting rabbit-sidecar application"
rabbitmq-plugins enable rabbitmq_auth_backend_http; rabbitmq-server
# starts the sidecar
java -jar /sidecar/demo-0.0.1-SNAPSHOT.jar
My original custom image that worked was this:
FROM rabbitmq:3.8.2-management
COPY rabbitmq.conf /etc/rabbitmq/rabbitmq.conf
CMD ["sh", "-c", "rabbitmq-plugins enable rabbitmq_auth_backend_http; rabbitmq-server"]
Which worked fine, but obviously I needed to do what I am doing because I want to be able to run another service within the same container as it requires it.
I did notice that there is a docker-entrypoint.sh in /usr/local/bin. Is this something to be considered in this context?

Related

Jenkins - Local checkout - Enable using script console

I am encountering below error. I am able to set the property using System.setProperty("hudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT", "true")
However, the issue still persists. Any pointers?
ERROR: Checkout of Git remote '<path to project folder>' aborted
because it references a local directory, which may be insecure.
You can allow local checkouts anyway by setting the system property
'hudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT' to true.
I found the info I needed and propably helps you too in
https://issues.jenkins.io/browse/JENKINS-68571:
So, follow these steps:
$ sudo systemctl stop jenkins
$ sudo systemctl edit jenkins
[Service]
Environment="JAVA_OPTS=-Dhudson.model.DirectoryBrowserSupport.CSP= -Dhudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT=true"
$ sudo systemctl restart jenkins
As per https://issues.jenkins.io/browse/JENKINS-68571:
it seems the System Property is read during initialization, thus changing it in Script Console does not change it.
In Script console use property on class directly:
hudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT = true
Note that neither the System Property nor the class property persist across restarts.
A persistent solution depends on how you installed / start Jenkins.
If you are running via java -jar ..., add the system property there (java -Dhudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT=true -jar ...).
Or, if you installed it using your systems package manager and your system is using systemd:
$ sudo systemctl edit jenkins
[Service]
Environment="JAVA_OPTS=-Dhudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT=true"
$ sudo systemctl restart jenkins

Kernel-slim UBI docker image not working with springBootUtility

Team, Is it possible to use springBootUtility with OpenLiberty kernel-slim UBI images (e.g. - kernel-slim-java8-openj9-ubi) ?
https://openliberty.io/docs/21.0.0.7/reference/command/springbootUtility-thin.html
Because, it's giving an error as
Step 3/11 : RUN springBootUtility thin --sourceAppPath=/staging/fat-order-0.0.1-SNAPSHOT.jar --targetThinAppPath=/staging/thin-order-0.0.1-SNAPSHOT.jar --targetLibCachePath=/staging/lib.index.cache
---> Running in 3023c669c4d7
/bin/sh: springBootUtility: command not found
The springBootUtility is only working with OpenLiberty full UBI images
The kernel-slim image does not appear to have that command at all. Compare kernel-slim:
bash-5.1$ docker run --rm -it openliberty/open-liberty:kernel-slim-java8-openj9-ubi ls /opt/ol/wlp/bin
auditUtility binaryLog.bat productInfo securityUtility.bat serverSchemaGen
auditUtility.bat featureUtility productInfo.bat server serverSchemaGen.bat
binaryLog featureUtility.bat securityUtility server.bat tools
To full:
bash-5.1$ docker run --rm -it openliberty/open-liberty:full-java8-openj9-ubi ls /opt/ol/wlp/bin
auditUtility binaryLog.bat featureUtility pluginUtility securityUtility.bat springBootUtility
auditUtility.bat client featureUtility.bat pluginUtility.bat server springBootUtility.bat
batchManager client.bat jaxb productInfo server.bat tools
batchManager.bat ddlGen jaxrs productInfo.bat serverSchemaGen
binaryLog ddlGen.bat jaxws securityUtility serverSchemaGen.bat
There appears to be a hole in the documentation, since nothing indicates you need to do this, but you need to install the springBoot feature into Open Liberty before the command will be added. Copy your server.xml with spring boot specified into the image, then run features.sh:
COPY --chown=1001:0 server.xml /config/
RUN features.sh
After that, springBootUtility will be placed in the /opt/ol/wlp/bin dir and should be on the path as well for further Dockerfile directives to use.

How to run spring-boot as a service in linux

I am trying to run a spring-boot application as a service in linux box so that I can start and stop it as a jenkins job.
As per the suggestions in for this question Spring Boot application as a Service I created the soft link
$sudo link -s /opt/jenkins/workspace/myapp/myapp.jar /etc/init.d/myapp
Now when I am trying to run it from the jenkins command prompt I get command not found
$ sudo /etc/init.d/myapp start
sudo: /etc/init.d/myapp: command not found
I am using spring boot 1.3 and java8
Did you check the executable flag (chmod +x myapp.jar)?

How to deploy SpringBoot Maven application with Jenkins ?

I have a Spring Boot application which runs on embedded Tomcat servlet container mvn spring-boot:run . And I don’t want to deploy the project as separate war to standalone Tomcat.
Whenever I push code to BitBucket/Github, a hook runs and triggers Jenkins job (runs on Amazon EC2) to deploy the application.
The Jenkins job has a post build action: mvn spring-boot:run, the problem is that the job hangs when post build action finished.
There should be another way to do this. Any help would be appreciated.
The problem is that Jenkins doesn't handle spawning child process from builds very well. Workaround suggested by #Steve in the comment (nohuping) didn't change the behaviour in my case, but a simple workaround was to schedule app's start by using the at unix command:
> echo "mvn spring-boot:run" | at now + 1 minutes
This way Jenkins successfully completes the job without timing out.
If you end up running your application from a .jar file via java -jar app.jar be aware that Boot breaks if the .jar file is overwritten, you'll need to make sure the application is stopped before copying the artifact. If you're using ApplicationPidListener you can verify that the application is running (and stop it if it is) by adding execution of this command:
> test -f application.pid && xargs kill < application.pid || echo 'App was not running, nothing to stop'
I find very useful to first copy the artifacts to a specified area on the server to keep track of the deployed artifacts and not to start the app from the jenkins job folder. Then create a server log file there and start to listening to it on the jenkins window until the server started.
To do that I developed a small shell script that you can find here
You will also find a small article explaining how to configure the project on jenkins.
Please let me know if worked for you. Thnaks
The nohup and the at now + 1 minutes didn't work for me.
Since Jenkins was killing the process spun in the background, I ensured the process to not be killed by setting a fake BUILD_ID to that Jenkins task. This is what the Jenkins Execute shell task looks like:
BUILD_ID=do_not_kill_me
java -jar -Dserver.port=8053 /root/Deployments/my_application.war &
exit
As discussed here.
I assume you have a Jenkins-user on the server and this user is the owner of the Jenkins-service:
log in on the server as root.
run sudo visudo
add "jenkins ALL=(ALL) NOPASSWD:ALL" at the end (jenkins=your Jenkins-user)
Sign In in Jenkins and choose your jobs and click to configure
Choose "Execute Shell" in the "Post build step"
Copy and paste this:
service=myapp
if ps ax | grep -v grep | grep -v $0 | grep $service > /dev/null
then
sudo service myapp stop
sudo unlink /etc/init.d/myapp
sudo chmod +x /path/to/your/myapp.jar
sudo ln -s /path/to/your/myapp.jar /etc/init.d/myapp
sudo service myapp start
else
sudo chmod +x /path/to/your/myapp.jar
sudo ln -s /path/to/your/myapp.jar /etc/init.d/myapp
sudo service myapp start
fi
Save and run your job, the service should start automatically.
This worked for me on jenkins on a linux machine
kill -9 $(lsof -t -i:8080) || echo "Process was not running."
mvn clean compile
echo "mvn spring-boot:run" | at now + 1 minutes
In case no process on 8080 it will print the message and will continue.
Make sure that at is installed on your linux machine. You can use
sudo apt-get install at
to install at

Tomcat not running on docker image

I installed tomcat7 on the image using Dockerfile through the command :
MAINTAINER Abc Xyz <abc#xyz.com>
RUN apt-get -qq update
RUN apt-get -y install openjdk-7-jre
RUN apt-get -y install tomcat7
EXPOSE 8080
When I build the image and try to run the following command :
sudo docker run -d -P abcxyz/tomcat service tomcat7 start
I don't get to see the tomcat page on the port to which it is mapped (say 49153)...
And when I run as a bash in the image and I try :
service tomcat7 start
Then also it fails to start the tomcat7 server.
I think that the problem is that image is unable to start the tomcat7 server. And I heard that docker images can't run any upstart services though I am not sure.
Anybody has any idea how to solve it?
Thanks.
change the command to
<path/to/tomcat>/bin/cataline.sh run
and this will make tomcat run in the forground
Just add:
--privileged=true
parameter with docker run command. Tomcat need extended privileges to run.
More informations there: https://docs.docker.com/reference/run/#runtime-privilege-linux-capabilities-and-lxc-configuration
It's not working, because the container will work for as long as the program you specified is running. The service tomcat7 start command finishes immediately.
You should run it like so:
docker run -dP abcxyz/tomcat catalina.sh run
This will make the container run as long as the command is executing. The way you were running it though is having the service as a background process.
use docker run with -d switch to run in detach mode. So it will run in background.
eg:
docker run -d abcd /path/catalina.sh run

Resources