forked from Azure-App-Service/nginx-fpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_container.sh
106 lines (90 loc) · 3.9 KB
/
init_container.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
# set -e
php -v
setup_mariadb_data_dir(){
test ! -d "$MARIADB_DATA_DIR" && echo "INFO: $MARIADB_DATA_DIR not found. creating ..." && mkdir -p "$MARIADB_DATA_DIR"
# check if 'mysql' database exists
if [ ! -d "$MARIADB_DATA_DIR/mysql" ]; then
echo "INFO: 'mysql' database doesn't exist under $MARIADB_DATA_DIR. So we think $MARIADB_DATA_DIR is empty."
echo "Copying all data files from the original folder /var/lib/mysql to $MARIADB_DATA_DIR ..."
cp -R --no-clobber /var/lib/mysql/. $MARIADB_DATA_DIR
else
echo "INFO: 'mysql' database already exists under $MARIADB_DATA_DIR."
fi
rm -rf /var/lib/mysql
ln -s $MARIADB_DATA_DIR /var/lib/mysql
chown -R mysql:mysql $MARIADB_DATA_DIR
test ! -d /run/mysqld && echo "INFO: /run/mysqld not found. creating ..." && mkdir -p /run/mysqld
chown -R mysql:mysql /run/mysqld
}
start_mariadb(){
service mysql start
rm -f /tmp/mysql.sock
ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock
# create default database 'azurelocaldb'
mysql -u root -e "CREATE DATABASE IF NOT EXISTS azurelocaldb; FLUSH PRIVILEGES;"
}
#unzip phpmyadmin
setup_phpmyadmin(){
test ! -d "$PHPMYADMIN_HOME" && echo "INFO: $PHPMYADMIN_HOME not found. creating..." && mkdir -p "$PHPMYADMIN_HOME"
cd $PHPMYADMIN_SOURCE
tar -xf phpMyAdmin.tar.gz -C $PHPMYADMIN_HOME --strip-components=1
cp -R phpMyAdmin-config.inc.php $PHPMYADMIN_HOME/config.inc.php
cp -R phpmyadmin-nginx.conf /etc/nginx/nginx.conf
cd /
rm -rf $PHPMYADMIN_SOURCE
if [ ! $WEBSITES_ENABLE_APP_SERVICE_STORAGE ]; then
echo "INFO: NOT in Azure, chown for "$PHPMYADMIN_HOME
chown -R www-data:www-data $PHPMYADMIN_HOME
fi
}
# setup server root
test ! -d "$HOME_SITE" && echo "INFO: $HOME_SITE not found. creating..." && mkdir -p "$HOME_SITE"
if [ ! $WEBSITES_ENABLE_APP_SERVICE_STORAGE ]; then
echo "INFO: NOT in Azure, chown for "$HOME_SITE
chown -R www-data:www-data $HOME_SITE
fi
# setup nginx log dir
# http://nginx.org/en/docs/ngx_core_module.html#error_log
# sed -i "s|error_log /var/log/error.log;|error_log stderr;|g" /etc/nginx/nginx.conf
echo "INFO: creating /run/php/php7.0-fpm.sock ..."
test -e /run/php/php7.0-fpm.sock && rm -f /run/php/php7.0-fpm.sock
mkdir -p /run/php
touch /run/php/php7.0-fpm.sock
chown www-data:www-data /run/php/php7.0-fpm.sock
chmod 777 /run/php/php7.0-fpm.sock
DATABASE_TYPE=$(echo ${DATABASE_TYPE}|tr '[A-Z]' '[a-z]')
if [ "${DATABASE_TYPE}" == "local" ]; then
echo "Starting MariaDB and PHPMYADMIN..."
echo 'mysql.default_socket = /run/mysqld/mysqld.sock' >> $PHP_CONF_FILE
echo 'mysqli.default_socket = /run/mysqld/mysqld.sock' >> $PHP_CONF_FILE
#setup MariaDB
echo "INFO: loading local MariaDB and phpMyAdmin ..."
echo "Setting up MariaDB data dir ..."
setup_mariadb_data_dir
echo "Setting up MariaDB log dir ..."
test ! -d "$MARIADB_LOG_DIR" && echo "INFO: $MARIADB_LOG_DIR not found. creating ..." && mkdir -p "$MARIADB_LOG_DIR"
chown -R mysql:mysql $MARIADB_LOG_DIR
echo "Starting local MariaDB ..."
start_mariadb
echo "Granting user for phpMyAdmin ..."
# Set default value of username/password if they are't exist/null.
DATABASE_USERNAME=${DATABASE_USERNAME:-phpmyadmin}
DATABASE_PASSWORD=${DATABASE_PASSWORD:-MS173m_QN}
echo "phpmyadmin username: "$DATABASE_USERNAME
echo "phpmyadmin password: "$DATABASE_PASSWORD
mysql -u root -e "GRANT ALL ON *.* TO \`$DATABASE_USERNAME\`@'localhost' IDENTIFIED BY '$DATABASE_PASSWORD' WITH GRANT OPTION; FLUSH PRIVILEGES;"
echo "Installing phpMyAdmin ..."
setup_phpmyadmin
fi
echo "Starting SSH ..."
service ssh start
echo "Starting php-fpm ..."
service php7.0-fpm start
chmod 777 /run/php/php7.0-fpm.sock
echo "Starting Nginx ..."
mkdir -p /home/LogFiles/nginx
if test ! -e /home/LogFiles/nginx/error.log; then
touch /home/LogFiles/nginx/error.log
fi
/usr/sbin/nginx