At first copy your script in /etc/init.d
then(for redhat based servers like centos)
chmod +x script.sh
chkconfig --add script.sh
chkconfig --level 0123456 script.sh on
For Debian based like ubuntu: help help2 help3
try:
cp /path/to/your/script.sh /etc/init.d/
chmod +x /etc/init.d/yourscript.sh
update-rc.d yourscript defaults
Runlevels are logical groups of tasks. Traditionally you have five run levels.
0 boot
1 single user
2 not used
3 multiuser
4 not used
5 gui
6 reboot