I am using RHEL 7 os with this i am using apache tomcat6. while try to start it using this command i am getting this message as:
Starting tomcat6: /etc/init.d/tomcat6: line 70: checkpid: command not found
and at line number 70 the code is as:
if checkpid $kpid 2>&1; then
echo "process allready running"
return -1
else
echo "lock file found but no process running for pid $kpid, continuing"
fi
after this execute the command i got process id for tomcat by this command:
[root#localhost ~]# ps -ef | grep tomcat
root 14074 13882 0 01:50 pts/1 00:00:00 grep --color=auto tomcat
but my war file is not deployed and also localhost:8080 is not working.
Related
I'm trying to run mysqldump from Spring Boot.
OS: Ubuntu 20.04.4 LTS
Bash version: 5.0.17(1)-release
Spring Boot: 2.6.7
Java: openjdk version "11.0.15" 2022-04-19; OpenJDK Runtime Environment (build 11.0.15+10-Ubuntu-0ubuntu0.20.04.1); OpenJDK 64-Bit Server VM (build 11.0.15+10-Ubuntu-0ubuntu0.20.04.1, mixed mode, sharing)
MySQL: mysql Ver 8.0.29-0ubuntu0.20.04.3 for Linux on x86_64 ((Ubuntu))
$ groups mysql
mysql : mysql
$ groups tomcat
tomcat : tomcat www-data mysql
$ ps -ef | grep mysql
mysql 54024 1 0 May06 ? 00:20:19 /usr/sbin/mysqld
$ ps -ef | grep tomcat
tomcat 122584 1 1 04:44 ? 00:04:52 /usr/lib/jvm/java-11-openjdk-amd64/bin/java -Djava.util.logging.config.file=/opt/tomcat/tomcat9/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Xms512M -Xmx1024M -server -XX:+UseParallelGC -Dignore.endorsed.dirs= -classpath /opt/tomcat/tomcat9/bin/bootstrap.jar:/opt/tomcat/tomcat9/bin/tomcat-juli.jar -Dcatalina.base=/opt/tomcat/tomcat9 -Dcatalina.home=/opt/tomcat/tomcat9 -Djava.io.tmpdir=/opt/tomcat/tomcat9/temp org.apache.catalina.startup.Bootstrap start
-rwxr-xr-x 1 root root 7539680 May 4 12:36 /usr/bin/mysql
-rwxr-xr-x 1 root root 7458048 May 4 12:36 /usr/bin/mysqldump
-rwxr-xr-x 1 root root 66334800 May 4 12:36 /usr/sbin/mysqld
-rwxr-xr-x 1 root root 14560 Apr 23 13:02 /usr/lib/jvm/java-11-openjdk-amd64/bin/java
Java code to execute mysqldump:
final String cmd = "/usr/bin/mysqldump -u username -ppassword --no-tablespaces --add-drop-table --databases TheVegCat -r /var/storage/backup/MySQL.sql";
try {
Runtime.getRuntime().exec(cmd);
}
catch (final IOException e) {
log.warn("Database backup failure; IOException: {}", e.getMessage());
}
Tried to add user tomcat to mysql group and restarted Tomcat service, but nothing changed.
When I run this command from shell as a root user, it works.
Is there a way to make this work?
ls -ld /var/storage/backup
will tell you the permissions of the directory to which you're trying to write and thus possible solutions. If it's root-only write then you could add user tomcat to the root group and give the directory group-write perms. but I don't like it too much. I'd prefer to write to a different directory for the sole purposes of the app.
Don't forget to consume stderr and stdout when creating a process from Java.
So I deploy war files on a Linux box using java automatically
and the same commands are always used
ps -ef | grep java
kill - 9 (java process)
java -jar ROOT.war &>/dev/null &
However, I get different versions for it so like
ROOT_1.0.2.war
ROOT_1.0.3.war
ROOT_1.0.4.war
ROOT_1.0.5.war
I want the script to see the new .war and deploy it automatically
and keep it deployed which is why I use &>/dev/null & so it runs in the till it is killed again till the new version is put in that directory
echo Enter the name of the process you want to kill eg ROOT.war?
enter code here
read process
##Kill selected process
file="$process"
if [ -f "$file" ];
then
pkill -9 -f $process
echo process stopped >> satrixWar.txt
sleep 3s
## Start Up selected process
echo Enter the name of the process you want to start
read process2
java -jar $process2 &>/dev/null &
echo process starting up>> satrixWar.txt
else
echo "Process $process does not exist" >&2
fi
##Confirm new proess is up
echo What is currently installed >> satrixWar.txt
ps -ef | grep $process2 >> satrixWar.txt
mail -a text file path -s "name"
"email.com" < /dev/null
rm -rf War.txt
I want to start the WildFly 11 using the standalone-full.xml instead standalone.xml.
So I have to execute the command:
sh standalone.sh -c standalone-full.xml
inside folder wildfly-11.0.0.Final/bin/.
But if I want to start the WildFly in silence mode with nohup, it doesn't start with parameter -c standalone-full.xml.
I tried with:
nohup ./standalone.sh -b 0.0.0.0 -c standalone-full.xml >/dev/null 2>&1 &
But it does not work.
What is the correct command to start WildFly with standalone-full.xml in silence mode in Linux?
Server information: cat /etc/*-release
NAME="Red Hat Enterprise Linux Server"
VERSION="7.4 (Maipo)"
ID="rhel"
ID_LIKE="fedora"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="7.4"
PRETTY_NAME="Red Hat Enterprise Linux Server 7.4 (Maipo)"
CPE_NAME="cpe:/o:redhat:enterprise_linux:7.4:GA:server"
Thanks.
Use the below cammand.
nohup sh standalone.sh -c standalone-full.xml > /dev/null &
I'm new to Linux but having spent a whole day I Installed Java and Tomcat. My goal is to host an App with this Linux box. I know it all works fine from my windows based machine, but it is my laptop so I'm planning to use the Linux Box as my dedicated server.
I am following this tutorial . From this tutorial I have executed the following command :
cd /etc/init.d
vi tomcat
#!/bin/bash
# description: Tomcat Start Stop Restart
# processname: tomcat
# chkconfig: 234 20 80
JAVA_HOME=/usr/java/jdk1.7.0_05
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
CATALINA_HOME=/usr/share/apache-tomcat-7.0.29
case $1 in
start)
sh $CATALINA_HOME/bin/startup.sh
;;
stop)
sh $CATALINA_HOME/bin/shutdown.sh
;;
restart)
sh $CATALINA_HOME/bin/shutdown.sh
sh $CATALINA_HOME/bin/startup.sh
;;
esac
exit 0
chmod 755 tomcat
chkconfig --add tomcat
chkconfig --level 234 tomcat on
chkconfig --list tomcat
service tomcat start
After this command , tomcat is started at port 8082 . But when I restart pc , the tomcat is not started with boot of PC .
How can I do this ?
Since you use Red Hat you can use systemd for services.
Create a file /etc/systemd/system/tomcat.service:
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/java/jdk1.7.0_05
Environment=CATALINA_PID=/usr/share/apache-tomcat-7.0.29/temp/tomcat.pid
Environment=CATALINA_HOME=/usr/share/apache-tomcat-7.0.29
Environment=CATALINA_BASE=/usr/share/apache-tomcat-7.0.29
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Duser.timezone=UTC -Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'
ExecStart=/usr/share/apache-tomcat-7.0.29/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID
User=tomcat
Group=tomcat
[Install]
WantedBy=multi-user.target
I specified the script to start after syslog and network are enabled.
As we can see systemd handles the tomcat as a daemon and kills the PID.
With User and Group we specify the user and the group that the process should be run as.
Systemd will handle the upstart process and kill it using the PID.
To enable it to run then issue:
systemctl enable tomcat
systemctl start tomcat
Try to use this command instead:
sudo systemctl enable tomcat
I have this command in my deployment process. But I want this process to stop and then restart while deploying in linux server. I checked and found that this is simply a JAVA process, and I can't simply kill JAVA as other nimbus and supervisors are running too.
sudo nohup java -Droute=full -jar /opt/artifacts/project/project.jar --spring.config.location=/etc/project/application_full.properties >/dev/null 2>&1 &
So, how can I stop this process?
Your oneliner kill: (I know it's bad, but it should work)
ps -ef| grep "name_of_service" | grep -oP "root\s+(\d+)\s" | grep -oP "\d+" | kill
ps -ef finds the program line:
root 5727 1 0 11:38 ? 00:00:00 grep service
Then we use grep to remove parts we don't want.
And lastly pass the pid to kill.
ps: replace 'root' for the user you know run the service/pid you are looking for.