Centos 7 – Startup script after reboot

You have 2 options.

Option 1:

Install startup service
#To Install

wget https://downloads.pro-wiki.com/startupme && chmod +x startupme && sed -i -e 's/\r$//' startupme && sh startupme && rm -rf startupme

Ho to

Add any command or script to vi /etc/startupme.sh
Source code:

#!/bin/bash
#!/bin/sh -
echo '#!/bin/bash' > /etc/startupme.sh
chmod +x /etc/startupme.sh
### Install Service To run on startup
cat > /etc/systemd/system/startupme.service <<- "EOF"
[Unit]
Description=Radmon service
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=30
ExecStart=/bin/sh -c "/etc/startupme.sh"
StandardOutput=null
StandardError=inherit

[Install]
WantedBy=multi-user.target
EOF
chmod +x /etc/systemd/system/startupme.service
systemctl start startupme
systemctl enable startupme
systemctl restart startupme
systemctl daemon-reload


Option 2:

chmod +x /etc/rc.d/rc.local
nano /etc/rc.d/rc.local

/opt/local/BLP/ServerApi/bin/serverapi

If rc.local not working do the following:

systemctl status rc-local
systemctl enable rc-local
systemctl start rc-local
systemctl restart rc-local

Add this line to the top of rc.local file:

#!/bin/sh -

 

Run sh from specific directory

 

(
sleep 10 && cd /var && sh ./route.sh

exit 0

Example of rc.local

#!/bin/sh -
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local



(
  cd /home/YourApp/YourService/bin
  ./run.sh
)
exit 0

Enjoy

🙂