skip to Main Content

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

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search