Create script to stop and start Tomcat service

  1. Create a script file and add the following lines
#Use this script for tomcat running as a service

#Stop Tomcat
systemctl stop tomcat

#Wati for 60 seconds
sleep 60

#Start Tomcat
systemctl start tomcat

2. Make the script executable

chmod +x

3. Automate script execution

3.1 Open crontab for editing

crontab -e

3.2 Add a line to execute the script at specific time

0 0 * * * /path/to/

Now, your Tomcat Service should automatically stop and start according to the schedule you have set in the cron job. Adjust the timing and frequency in the cronjob as needed.