I have a script, it restarts tomcat in 2 minutes,, I would like that this script was started constantly after server restart, I will be grateful if someone shows how to do it?
#! /bin/bash sleep 120 systemctl restart tomcat
Read archwiki about systemd/Timer or maybe original freedesktop documentation about systemd.timer .
Create a file my_super_tomcat_restarter.timer
in /etc/systemd/system/
:
[Unit]
Description=Superbly restart my tomcat service every 120 seconds!
[Timer]
OnBootSec=120sec
OnUnitActiveSec=120sec
[Install]
WantedBy=timers.target
Create a file my_super_tomcat_restarter.service
in /etc/systemd/system/
with the content:
[Unit]
Description=Superbly restart tomcat service!
[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl restart tomcat
Execute from your terminal as root
:
systemctl enable my_super_tomcat_restarter.timer
The timer should fire in 120 seconds and execute my_super_tomcat_restarter.service
which in turn will restart your tomcat service.
either add it in init.d
or systemd
based on your Linux distribution of yours. in both cases you have to be root to add your script.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.