#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

init_path=/etc/init.d
Root_Path=`cat /var/bt_setupPath.conf`
Setup_Path=$Root_Path/server/mysql
Data_Path=$Root_Path/server/data

soft_start(){
    ${init_path}/nginx start
    ${init_path}/php-fpm-74 start
    ${init_path}/pure-ftpd start
    ${init_path}/bt restart
    pkill crond
    /sbin/crond
    /usr/sbin/sshd -D &
}

is_empty_Data(){
    return `ls -A ${Data_Path}/|wc -w`
}

init_mysql(){
# initialize_mysql
    if [ -f /init_mysql.sh ];then
        sh /init_mysql.sh
        rm -f /init_mysql.sh
    fi
}

start_mysql(){
    chown -R mysql:mysql ${Data_Path}
    chgrp -R mysql ${Setup_Path}/.
    ${init_path}/mysqld start
    rm -f /init_mysql.sh
}

soft_start > /dev/null
is_empty_Data > /dev/null
if [ $? == 0 ];then
    init_mysql > /dev/null
else
    start_mysql > /dev/null
fi
tail -f /dev/null
