how can I schedule a custom script to run whenever I restart a service
Question:
I wish to know how can I schedule a custom script to run whenever I restart a service.
My use case is that I have to run several commands whenever I restart my Tomcat Service. I want to know if there is a way I can write a script and schedule it to run whenever I restart the Tomcat service.I have setup the tomcat script as a systemd service. I am using Cent OS 7 x64.
Reply:
(you probably only need to replace httpd by tomcat everywhere).
Simply create an new systemd httpd.service
file in /etc
which includes and overrides part of the one in /lib
. For example, create /etc/systemd/system/httpd.service
to contain
.include /lib/systemd/system/httpd.service
[Service]
ExecStartPre=/home/meuh/myscripttorun some pre args here
ExecStartPost=/home/meuh/myscripttorun some post args here
Any ExecStartPre
lines will be executed before the apache ExecStart
line, and similarly any ExecStartPost
will run after apache has started.
httpd.service
file in /etc
which includes and overrides part of the one in /lib
. For example, create /etc/systemd/system/httpd.service
to contain.include /lib/systemd/system/httpd.service
[Service]
ExecStartPre=/home/meuh/myscripttorun some pre args here
ExecStartPost=/home/meuh/myscripttorun some post args here
ExecStartPre
lines will be executed before the apache ExecStart
line, and similarly any ExecStartPost
will run after apache has started.
how can I schedule a custom script to run whenever I restart a service
Reviewed by Ubuntu-tuts
on
06:29:00
Rating:
Post a Comment