CentOS / RHEL 7 : How to create custom daemon service
Posted: 25 Jul 2018, 13:08pm - Wednesday

First, create the script you want to run...

# vi /root/firewalld.sh
#!/bin/bash
iptables -F
iptables -L
Then make this executable...
chmox u+x /root/firewalld.sh
then you need to create the daemon service
# vi /etc/systemd/system/sample.service
[Unit]
Description=Description for sample script goes here
After=network.target

[Service]
Type=simple
ExecStart=/root/firewalld.sh
TimeoutStartSec=0

[Install]
WantedBy=default.target
definitions:
After= : If the script needs any other system facilities (networking, etc), modify the [Unit] section to include appropriate After=, Wants=, or Requires= directives.
Type= : Switch Type=simple for Type=idle in the [Service] section to delay execution of the script until all other jobs are dispatched
WantedBy= : target to run the sample script in
then cast the commands below:
# systemctl daemon-reload
# systemctl enable sample.service
# systemctl start sample.service
# systemctl reboot
after rebooting, your script should be executed.   Reference: https://www.thegeekdiary.com/centos-rhel-7-how-to-make-custom-script-to-run-automatically-during-boot/