Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a bash script before httpd service is started with systemd

I want to run a custom bash script before httpd service is started with systemd. I'm using Centos 7.

Any idea?

Kind regards.

like image 756
Javi Avatar asked Mar 24 '17 12:03

Javi


People also ask

How do I run a script as daemon?

We can use systemd unit files to launch our script at boot. Unit files describe how the system should execute the given program. We set the user that the script will run with the User= option and the path to the script with the ExecStart= option. The various options are documented in the systemd.


1 Answers

Assuming your httpd service is named httpd.service, create a directory /etc/systemd/system/httpd.service.d; and create a file named run-my-script-first.conf (or whatever you like) within it with the following contents:

[Service]
ExecStartPre=/path/to/your/script
like image 192
Charles Duffy Avatar answered Oct 08 '22 20:10

Charles Duffy