I want to profile tomcat server with a java profiler. My profiler runs from the script say run.sh which looks like below:
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
JAVACMD="$JAVA_HOME/bin/java"
else
JAVACMD="`which java`"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly; cannot execute: $JAVACMD"
exit 1
fi
java -javaagent:lib/jborat-agent.jar \
-Dch.usi.dag.jborat.exclusionList="conf/exclusion.lst" \
-Dch.usi.dag.jborat.liblist="conf/lib.lst" \
-Dch.usi.dag.jp2.outputFilePrefix="output" \
-Dch.usi.dag.jborat.instrumentation="ch.usi.dag.jp2.instrument.AddInstrumentation" \
-Dch.usi.dag.jp2.dumpers="ch.usi.dag.jp2.dump.xml.XmlDumper" \
-Dch.usi.dag.jborat.codemergerList="conf/codemerger.lst" \
-Xbootclasspath/p:./lib/Thread_JP2.jar:lib/jborat-runtime.jar:lib/jp2-runtime.jar/jp2.jar/jborat-agent.jar/jborat.jar $*
Could somebody please guide me how can I include this profiler in tomcat ?
Is it possible to write something like this CATALINA_OPTS="$CATALINA_OPTS -javaagent:run.sh" in catalina.sh ?
I would really appreciate any help regarding this.
Thanks.
I tried adding options of run.sh (profiler) to setenv.sh as below but does not work. It does not give any error but The server is not starting. I dont know why.
Here is my setenv.sh file:
#!/bin/sh
export CATALINA_OPTS="java -javaagent:lib/jborat-agent.jar \
-Dch.usi.dag.jborat.exclusionList="conf/exclusion.lst" \
-Dch.usi.dag.jborat.liblist="conf/lib.lst" \
-Dch.usi.dag.jp2.outputFilePrefix="output" \
-Dch.usi.dag.jborat.instrumentation="ch.usi.dag.jp2.instrument.AddInstrumentation" \
-Dch.usi.dag.jp2.dumpers="ch.usi.dag.jp2.dump.xml.XmlDumper" \
-Dch.usi.dag.jborat.codemergerList="conf/codemerger.lst" \
-Xbootclasspath/p:./lib/Thread_JP2.jar:lib/jborat-runtime.jar:lib/jp2-runtime.jar/jp2.jar/jborat-agent.jar/jborat.jar "
I already answered your exact same question yesterday. Briefly, you want this:
$ export CATALINA_OPTS="-javaagent:lib/jborat-agent.jar -Xss256m -Xms256m \ -Dch.usi.dag.jborat.exclusionList="conf/exclusion.lst" \ -Dch.usi.dag.jp2.dumpers="ch.usi.dag.jp2.dump.xml.XmlDumper" \ -Xbootclasspath/p:./lib/Thread_JP2.jar:lib/jborat-runtime.jar:lib/jp2-runtime.jar"
$ $CATALINA_HOME/bin/startup.sh
I don't understand why you need more than that: your script just adds a bunch of system properties to the JVM launcher: you can do that with $CATALINA_OPTS. If you want to set them somewhat permanently, put the export into bin/setenv.sh and it will automatically be run every time you run bin/startup.sh (and bin/shutdown.sh for that matter).
Related
I've already built and created the libraries I needed for my project for Windows [.dll] and Mac OS X (Arm based) [.dylib]. The fact is that, given the processor difference, I don't know If I can make the *.so libraries ( at least I think that the extension of the libraries , from what I've found after searching A LOT ).
If someone knows and says otherwise, I'll take as given that it's not possible to do it.
The method I've used is the one via cmake.
Example :
cmake -DCMAKE_SYSTEM_PROCESSOR=arm64 \
-DCMAKE_OSX_ARCHITECTURES=arm64 \
-DWITH_OPENJPEG=OFF \
-DWITH_IPP=OFF \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_INSTALL_PREFIX=/usr/local/opencv \
-D JAVA_INCLUDE_PATH=$JAVA_HOME/include \
-D JAVA_AWT_LIBRARY=$JAVA_HOME/jre/lib/amd64/libawt.so \
-D JAVA_JVM_LIBRARY=$JAVA_HOME/jre/lib/arm/server/libjvm.so \
-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.5.5/modules \
-D WITH_FFMPEG=OFF \
-D WITH_OPENCL=OFF \
-D BUILD_opencv_java=ON \
-D OPENCV_ENABLE_NONFREE=ON \
-D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=OFF \
-D BUILD_ZLIB=OFF \
-D BUILD_EXAMPLES=ON ../opencv-4.5.5
I know the question is almost stupid, but I'll still want to be sure. Thank you guys <3
I have a file.sh with this, when run show : TERM environment variable not set.
smbmount //172.16.44.9/APPS/Interfas/HERRAM/sc5 /mnt/siscont5 -o
iocharset=utf8,username=backup,password=backup2011,r
if [ -f /mnt/siscont5/HER.TXT ]; then
echo "No puedo actualizar ahora"
umount /mnt/siscont5
else
if [ ! -f /home/emni/siscont5/S5.TXT ]; then
echo "Puedo actualizar... "
touch /home/emni/siscont5/HER.TXT
touch /mnt/siscont5/SC5.TXT
mv -f /home/emni/siscont5/CCORPOSD.DBF /mnt/siscont5
mv -f /home/emni/siscont5/CCTRASD.DBF /mnt/siscont5
rm /mnt/siscont5/SC5.TXT
rm /home/emni/siscont5/HER.TXT
echo "La actualizacion ha sido realizada..."
else
echo "No puedo actualizar ahora: Interfaz exportando..."
fi
fi
umount /mnt/siscont5
echo "/mnt/siscont5 desmontada..."
You can see if it's really not set. Run the command set | grep TERM.
If not, you can set it like that:
export TERM=xterm
Using a terminal command i.e. "clear", in a script called from cron (no terminal) will trigger this error message. In your particular script, the smbmount command expects a terminal in which case the work-arounds above are appropriate.
You've answered the question with this statement:
Cron calls this .sh every 2 minutes
Cron does not run in a terminal, so why would you expect one to be set?
The most common reason for getting this error message is because the script attempts to source the user's .profile which does not check that it's running in a terminal before doing something tty related. Workarounds include using a shebang line like:
#!/bin/bash -p
Which causes the sourcing of system-level profile scripts which (one hopes) does not attempt to do anything too silly and will have guards around code that depends on being run from a terminal.
If this is the entirety of the script, then the TERM error is coming from something other than the plain content of the script.
You can replace :
export TERM=xterm
with :
export TERM=linux
It works even in kernel with virgin system.
SOLVED: On Debian 10 by adding "EXPORT TERM=xterm" on the Script executed by CRONTAB (root) but executed as www-data.
$ crontab -e
*/15 * * * * /bin/su - www-data -s /bin/bash -c '/usr/local/bin/todos.sh'
FILE=/usr/local/bin/todos.sh
#!/bin/bash -p
export TERM=xterm && cd /var/www/dokuwiki/data/pages && clear && grep -r -h '|(TO-DO)' > /var/www/todos.txt && chmod 664 /var/www/todos.txt && chown www-data:www-data /var/www/todos.txt
If you are using the Docker PowerShell image set the environment variable for the terminal like this with the -e flag
docker run -i -e "TERM=xterm" mcr.microsoft.com/powershell
I'm tasked with creating a very simple, web browser accessible gui that can run a specific java file within a docker container. To do this I've chosen to set up a php-apache server that serves an index.php document with the gui. The Dockerfile looks like this:
FROM php:7.0-apache
COPY src /var/www/html
EXPOSE 80
This gets the gui (index.php is inside the src folder) I've written up and running no problem, but it cannot access and run the required java files (obviously, since this creates a separate container).
The Question:
How can I set up a php-apache server inside the existing Dockerfile (provided below) doing the same thing as the Dockerfile above? My aim is to run the java file using php scripts and display the result to the user.
FROM openjdk:8-jre-slim
WORKDIR /usr/src/app
COPY ["./build/libs/*.jar", "./fooBar.jar"]
ENV JAVA_OPTS=${FOO_JAVA_OPTS}
CMD ["/usr/bin/tail", "-f", "/dev/null"]
I have not written the java file myself, only being tasked with running specific commands using it.
As it is Debian based images. one way of doing it, install packages in the container and create the new images from that.
root#310c94d8d75f:/usr/src/app# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
2: root#310c94d8d75f:/usr/src/app# apt update
3- root#310c94d8d75f:/usr/src/app# apt install apache2
4- root#310c94d8d75f:/usr/src/app# apt install php
finally run : docker commit
after this, you will get a new image with the mentioned name.
Ref: https://docs.docker.com/engine/reference/commandline/commit/
2: you can add the same command in Dockerfile and rebuild.
FROM openjdk:8-jre-slim
WORKDIR /usr/src/app
COPY ["./build/libs/*.jar", "./fooBar.jar"]
ENV JAVA_OPTS=${FOO_JAVA_OPTS}
CMD ["/usr/bin/tail", "-f", "/dev/null"]
RUN apt update && apt install apache2 -y && apt install php -y
There appears to be no easy way of merging images like I initially hoped (You cannot have multiple FROM statements in your Dockerfile). What I eventually ended up doing was to manually merge the two images (openjdk and php) into something like this:
FROM php:7.0-apache
ENV LANG C.UTF-8
RUN { \
echo '#!/bin/sh'; \
echo 'set -e'; \
echo; \
echo 'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"'; \
} > /usr/local/bin/docker-java-home \
&& chmod +x /usr/local/bin/docker-java-home
RUN ln -svT "/usr/lib/jvm/java-8-openjdk-$(dpkg --print-architecture)" /docker-java-home
ENV JAVA_HOME /docker-java-home/jre
ENV JAVA_VERSION 8u212
ENV JAVA_DEBIAN_VERSION 8u212-b01-1~deb9u1
RUN set -ex; \
if [ ! -d /usr/share/man/man1 ]; then \
mkdir -p /usr/share/man/man1; \
fi; \
apt-get update; \
apt-get install -y --no-install-recommends openjdk-8-jre-headless="$JAVA_DEBIAN_VERSION"; \
rm -rf /var/lib/apt/lists/*; \
[ "$(readlink -f "$JAVA_HOME")" = "$(docker-java-home)" ]; \
update-alternatives --get-selections | awk -v home="$(readlink -f "$JAVA_HOME")" 'index($3, home) == 1 { $2 = "manual"; print | "update-alternatives --set-selections" }'; \
update-alternatives --query java | grep -q 'Status: manual'
COPY ["./build/libs/*.jar", "./FooBar.jar"]
ENV JAVA_OPTS=${FOO_JAVA_OPTS}
COPY gui/src /var/www/html
EXPOSE 80
Both are Debian based images so the merging were relatively easy (I also removed much of the cluttering comments from the original image source) and since the openjdk image were simpler, I added it on top of the php image instead of the other way around.
Hi i have a problem with code duplication while building rpm package.
I have a spec like this:
Summary : ${product.id} ${rpmType}
Name : ${product.id}_${rpmType}
.....
%build
%install
%files
%defattr(-,root,java,750)
%{home}
%clean
rm -rf %{buildroot}
%pre
CHECK_PAUSE=2;
echo -n "Stopping tomcat";
sh %{binary}/shutdown.sh
rc=0
while [ "$rc" == 0 ]; do
sleep $CHECK_PAUSE;
wget -q -O /dev/null -S http://localhost:8080/some-server/test;
rc=$?;
done;
echo "Tomcat: STOPPED"
mv %{home}/%{warname} %{home}/%{warname}.`date +%Y%d%m`
rm -rf %{home}/some-server
echo done.
%post
CHECK_PAUSE=2;
echo -n "Starting tomcat";
sh %{binary}/startup.sh
rc=1
while [ "$rc" -ne 0 ]; do
sleep $CHECK_PAUSE
wget -q -O /dev/null -S http://localhost:8080/some-server/test
rc=$?
done
echo "Tomcat: STARTED"
%preun
if [ "$1" == "0" ]; then
#STOP TOMCAT HERE SAME WAY AS IN PRE
fi
%postun
if [ "$1" == "0" ]; then
#START TOMCAT HERE SAME WAY AS IN POST
fi
The scripts which are going to be executed in preun and postun sections are the same as in pre and post sections. But I don't want just copy/paste them. Is there some sophisticated solution to avoid code duplication here?
Here is a possible solution:
Create separate files for each piece of reusable shell script code.
Create a sort of pre-processor (possibly another shell script) that inserts the files created in Step 1 above into the spec file under the appropriate scriplet label (i.e. %pre, %post, %preun, %postun).
If you are using a source control management system, you might want to track these additional files as well.
Using openSUSE, I downloaded the Oracle rpms for jdk1.6.0_24 and I want to set the java home environment variable to /usr/java/jdk1.6.0_24 but the /etc/alternatives system is unable to automatically detect this installed JDK. Update-alternatives , or whatever just doesn't find the jdk.
So, I want to detect the JAVA home manually in a BASH script.
If I run this command: sudo find /usr -name 'jdk1.6*' , I get this result:
/usr/java/jdk1.6.0_24
How do pipe that result into a environment variable? I want to do something like
#!/bin/bash
read in JAVA_HOME var from a file
if file doesnt exist
sudo find /usr -name 'jdk1.6*'
prompt user for which jdk is correct
set that choice to a variable
add the JDK to alternatives if it is missing
save variable to a file and dont prompt next time
set the alternatives java choice
fi
echo $JAVA_HOME
something like
#!/bin/bash
function validate_java_home {
if [ -z ${JAVA_HOME} ]
then
# do something if the file doesn't provide ${JAVA_HOME}
else
if [ ! -e ${JAVA_HOME} ]
then
# do something if the file provides a non existent ${JAVA_HOME}
fi
fi
}
if [ ! -e ${YOUR_FILE_NAME_CONTAINING_JAVA_HOME} ]
then
JAVA_HOME_CANDIDATES=$(find /usr -name 'jdk1.6*')
echo "Found the following candidates for JAVA_HOME, reply with the one you want then press return"
echo ""
echo $JAVA_HOME_CANDIDATES
read USER_SUBMITTED_JAVA_HOME
echo "You chose $USER_SUBMITTED_JAVA_HOME"
JAVA_HOME=${USER_SUBMITTED_JAVA_HOME}
else
. ${YOUR_FILE_NAME_CONTAINING_JAVA_HOME}
fi
validate_java_home
export ${JAVA_HOME}
I haven't tested that but hopefully you get the gist (and I'd say using select as per glenn jackman's answer is more concise/friendly, didn't know that existed so I'm glad I read this Q!)
oldIFS="$IFS"
IFS=$'\n'
choices=( $(find /usr/java -type d -maxdepth 1 -print) )
select choice in "${choices[#]}"; do
[[ "$choice" ]] && break
done
IFS="$oldIFS"
export JAVA_HOME="$choice"
Not sitting at a linux terminal, but this should get you going:
...
jdkpath=`sudo find /usr -name 'jdk1.6*'`
export JAVA_HOME=$jdkpath
...
Adjust as needed.
Based on Matt's answer , here is the script I am using:
#!/bin/bash
# JAVA_HOME script for RPM based java installations
# http://www.oracle.com/technetwork/java/javase/install-linux-64-rpm-138254.html
# examine and understand /etc/alternatives before you run this
cd $SITE_HOME
function set_java_home {
if [ -z $JAVA_HOME ]; then
echo "Using default value for JAVA_HOME: /usr/java/default"
JAVA_HOME=/usr/java/default
fi
export -p JAVA_HOME
echo $JAVA_HOME > java.home.config
echo "JAVA_HOME variable set to $JAVA_HOME ."
}
if [ -f java.home.config ]; then
JAVA_HOME=$(<java.home.config)
else
JAVA_HOME_CANDIDATES=$(find /usr -type d -name 'jdk1.6*')
echo "Found the following candidates for JAVA_HOME. Pick one: "
echo "---"
echo $JAVA_HOME_CANDIDATES
echo "---"
read USER_SUBMITTED_JAVA_HOME
echo "You chose $USER_SUBMITTED_JAVA_HOME ."
JAVA_HOME=${USER_SUBMITTED_JAVA_HOME}
fi
# Set the variable
set_java_home