How to auto start apache tomcat server - java

I can view the webpage after deploying the war file.when i open the page for next day i cannot view the page again after restarting the apache tomcat server the page opens.

You must have shut down the machine. When you come on next day and access the same URL then you won't be able to see that page. You will have to restart the tomcat server again to see that page.

I assume you use Linux and encountered the same issue when security patches/ OS hardening is performed on the server where apache tomcat runs. Below is the way I tackled the problem starting tomcat right after server reboots.
You will need to use CronScheduler and is pretty easy. The Cron daemon is a built-in Linux utility that runs processes on your system at a scheduled time.
Open a Terminal
Type --> crontab –e
Add following Line into Crontab --> #reboot [path to tomcat`s startup.sh shell script in tomcat`s bin directory]
Press ESC key and Press ':' and Type "wq" (Save the changes into Cron via VIM/ VI)
Type crontab -l (This will show you the reboot statement added means all OK)
The job defined by this string runs at startup, immediately after Linux reboots.

Related

Catalina.out doesn't exist

I want to read my console output logs, and I know that they are stored into "log" folder under the file catalina.out, but it doesn't exists! I have tried in different ways with no results. I don't know how to figure it out, I just want to see my java outputs logs
If the catalina.out is deleted after tomcat is stopped, it will create a new catalina.out once tomcat starts again and it is totally safe.
But if you remove the catalina.out while tomcat is running, it will keep on logging to catalina.out which is removed already (reference of the file is hold by the tomcat) hence the space will not be released. So you will need to restart the tomcat sever to release the space. It is not recommended.
Start/ Run Tomcat server and it should create catalina.out file without any error.
Following are the multiple ways of running tomcat. Just indicated in detail so this would help someone in need.
./catalina.sh run
Passing "run" argument for catalina.sh --> starts the Tomcat in the foreground and displays the running logs in the same console. when the console terminal is closed it will terminate the tomcat.
./catalina.sh start
Passing "start" argument for catalina.sh --> starts the Tomcat in the background. Since in background no issues closing down the terminal. The logs need to be viewed as below: tail -f $CATALINA_HOME/logs/catalina.out
./startup.sh
The last way is firing the startup.sh to start your Tomcat server. If you Vi the script you can see it calls catalina.sh script passing start as the argument. This will be running in background as well.
Now check your tomcat log directory and you should find the catalina.out
From catalina.sh , it says :
# CATALINA_OUT (Optional) Full path to a file where stdout and stderr
# will be redirected.
# Default is $CATALINA_BASE/logs/catalina.out
So , look at your script that is used to start Tomcat to find out what the value of the environment variable CATALINA_OUT.
go to the bin folder of tomcat and run below script
./catalina.sh start
now catalina.out exist in logs folder
When we upgraded our Beanstalks to Tomcat 8.5 with Corretto 11 running on 64bit Amazon Linux 2, catalina.out no longer existed and not all logs were present in catalina.date.log. We re-established the catalina.out with the following file dropped into /etc/rsyslog.d/catalina.conf
$umask 0000
$FileCreateMode 0644
template(name="Tomcat" type="string" string="%msg%\n") {
property(name="msg")
}
if $programname == 'tomcat' then {
action(type="omfile" file="/var/log/tomcat/catalina.out" template="Tomcat")
}
if $programname == 'server' then {
action(type="omfile" file="/var/log/tomcat/catalina.out" template="Tomcat")
}
you will want to restart rsyslog afterwards.
service rsyslog restart

Spring boot App not working after ssh logout

So I'm deploying my Spring Boot application on an Ubuntu LTS Server. It is built with maven and running with embedded Tomcat.
I'm still new to the deployment process, what I did was:
Log into server via ssh
use scp to upload my_application.zip
unzip it in ssh
java -jar my_application.jar
Now all of that works perfectly fine and I've been using it like that for quiet some time. Now I have to make the Application to stay online and available after logging out of the shell.
I have read some documentation about running processes in background on Linux and I've tried it with nohup java -jar myApplication.jar &, with the screen command and with bg. All of them worked fine while I'm logged into the ssh.
Here comes my problem:
As soon as I end the ssh session the Web App is still available (so the process clearly didn't stop) but it just looks & behaves really weird.
CSS is not applied, JS does not work etc.
My guess would be that some paths or file system accesses are messed up, but I have no idea at all how that could origin from the ssh session.
(When I log back into ssh everything is working fine again)
Would be great if someone has a clue here
If your server has encrypted home directory, it will get re-encrypted once you log out and therefore your script will stop working. It does not have a lot of sense to have encrypted homes on servers so you can disable it.
Or just run the script from different directory and avoid working with files under home directory.
I think you should use systemd for this case.
Also You can add new system user for your app.
You can find more information here:
Spring Boot: 59.2.2 Installation as a systemd service
Ubuntu Wiki: Systemd For UpstartUsers
For example:
Create file myunit.service
[Unit]
Description=MySpringService
After=syslog.target
After=network.target
After=mysql.service
[Service]
Type=forking
PIDFile=/work/www/myunit/shared/tmp/pids/service.pid
WorkingDirectory=/work/www/myunit/current
User=myunit
Group=myunit
Environment=RACK_ENV=production
OOMScoreAdjust=-1000
ExecStart=/usr/local/bin/bundle exec service -C /work/www/myunit/shared/config/service.rb --daemon
ExecStop=/usr/local/bin/bundle exec service -S /work/www/myunit/shared/tmp/pids/service.state stop
ExecReload=/usr/local/bin/bundle exec service -S /work/www/myunit/shared/tmp/pids/service.state restart
TimeoutSec=300
[Install]
WantedBy=multi-user.target
Copy file to /etc/systemd/system/
Run:
systemctl enable myunit
systemctl start myunit

Install4j: installing a service

For my installation, I am trying to install both my database server (which is postgresql) and my application server as services. I know it is possible to install postgres using pg_ctl from console by starting it as admin. But as far I know it is not possible for java to start cmd.exe in administrative mode. So I was hoping to be able to achieve it by Install4j. I saw the sample "hello" project. But there it creates a launcher. But in my case for postgresql I need to run the pg_ctl along with some arguments. And for application server I have my own batch file as the executor. For PGSQL I have tried giving windows arguments i.e. -N service_name -D data_folder. But for both cases it fails to start the service. I also tried manually from the Services menu in Windows it fails to start. I have the account setting as "local system".
I have also tried running pg_ctl using "run executable or batch file" action but still I could not find the service in the windows services list, not to mention the same arguments work fine from command prompt. I have added a figure of the action properties I used in the project.
If your installer has executed a "Request privileges" action and you execute pg_ctl.exe with a "Run executable or batch file" action, it will be executed with admin privileges, because the the default value of the "Action elevation type" property of that action is "Elevate to maximum available privileges".

Tomcat doesn't start automatically in windows

I installed Tomcat 6.0 in my windows server 2008 R2.I setted
CATALINA_HOME=C:\Program Files\Apache Software Foundation\Tomcat 6.0
JAVA_HOME=C:\Program Files\Java\jdk1.6.0_21.
When I try to open with startup.bat.Tomcat is running.I can reach the localhost.But I want to get these things with automatically.When I open the start task manager.I cant see any tomcat or apache services.Just I can reach only with command prompt method(you can see the running black screen to below).How to open automatically without entering this parameter.
Edit: Yes,I want to start tomcat with my System starts
Last Edit:I found the main error.Windows doesnt recognize the tomcat.How to define tomcat to windows being a service?
To automatically run Tomcat when Windows starts, you need to run Tomcat as a service, which is documented here:
https://tomcat.apache.org/tomcat-6.0-doc/windows-service-howto.html
https://tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.html
https://tomcat.apache.org/tomcat-8.0-doc/windows-service-howto.html

Log File not Creating after tomcat restart

I have an ec2 instance from which i am remotely logging in to a remote EC2 server (as ec2-user) on which my application is hosted in its tomcat server.
The tomcat server generates a log file for this particular application.
If i delete the log file (test_app.log) and restart the server manually using startup.sh command a new log file with same name gets created but when i try to do this by remote login it is not working. The tomcat server is restarting (i have verified it on my browser) but the log file do not get genrated.
As i want a separate log for all my application runs , i am first stopping the tomcat by killing it, then i move the test_app.log to other name with time stamp, and then restart the server.
when i use automated script to ssh for the first time everything happens as planned above but from the next iteration nothing happens.Even after using touch no new file gets created.
Please note if i do entire process manually ,all the commands run properly and everything works fine.
ssh -i $Public_Key_Loc -tt $Remote_user#$PrivateIpSPL <<-ENDSSH
sudo su - spluser
kill -9 $(ps -elf | grep tomcat|cut -d ' ' -f6 | head -n 1)
mv /opt/tomcat/current/logs/spl/spl-test-tool/test_app.log /opt/tomcat/current/logs/spl/spl-test-tool/$(date "+%Y.%m.%d-%H.%M.%S").test_app.log
touch test_app.log
chown spluser:splgrp test_app.log
chmod 644 test_app.log
/opt/tomcat/current/bin/startup.sh
exit
exit
ENDSSH
i think the culprit is touch command ,the file will get created at the current folder , i think you should provide absolute path for that too.

Categories

Resources