July 8, 2016

Centos - running commands at system initialization

Did this to restart DB and Web server during system boot.

1. Create a initialization script at /root/instance_init.sh

Commands are chained using && to make sure it executes in sequence

#!/bin/bash
echo "Step: staring mysql" &&
service mysqld start &&
echo "Step: restoring database" &&
runuser -l auser -c '/home/auser/mysqlrestore/s3_to_db_restore.sh' &&
echo "Step: starting jboss" &&
runuser -l auser -c '/usr/local/jboss-6.1.0.Final/bin/startjboss.sh'

2. Open > vi /etc/rc.d/rc.local
append a line:
sh /root/instance_init.sh


No comments:

Post a Comment