Start service at uci-defaults stage / start mariadb via uci-defaults?

trying to automate database creation by uci-defaults script but mysql doesn't start yet, infinite loop if i'm using until

...
[ -s "/etc/mysql/conf.d/50-server.cnf" ] || exit 1;
[ "$(uci -q get mysqld.general)" = "mysqld" ] || exit 1;
uci set mysqld.general.enabled='1';
uci commit mysqld.general;
# change root password
mysql_bind=$(cat /etc/mysql/conf.d/50-server.cnf | grep '^bind-address' | sed 's| ||g' | cut -d'= ' -f2);
mysql_port=$(cat /etc/mysql/conf.d/50-server.cnf | grep '^port' | sed 's| ||g' | cut -d'= ' -f2);
# [ -n "${mysql_bind:?}" ] || exit 1;
# [ -n "${mysql_port:?}" ] || exit 1;
# /etc/init.d/mysqld start && until mysqladmin ping -h "${mysql_bind}" -P "${mysql_port}"; do sleep 1; done;
# mysqladmin -u root password "${mysql_root_password:?}";
# create wordpress database
[ "$(mysqlshow --user="${mysql_wp_database_user:?}" --password="${mysql_wp_database_pass:?}" "${mysql_wp_database_name:?}" | grep 'Database:' | wc -l)" -gt 0 ] || {
	mysql -u root -e "create database ${mysql_wp_database_name:?};";
	mysql -u root -e "grant all privileges on ${mysql_wp_database_name:?}.* TO ${mysql_wp_database_user:?}@localhost identified by '${mysql_wp_database_pass:?}';";
	mysql -u root -e "flush privileges;";
};
...
...
+ uci commit nginx.ariang
+ '[' -s /etc/mysql/conf.d/50-server.cnf ]
+ uci -q get mysqld.general
+ '[' mysqld '=' mysqld ]
+ uci set 'mysqld.general.enabled=1'
+ uci commit mysqld.general.enabled
+ mysqlshow '--user=my_wp_user' '--password=my_wp_pass' my_wp_db
+ grep Database:
+ wc -l
mysqlshow: Can't connect to local server through socket '/var/run/mysql/mysql.sock' (2)
+ '[' 0 -gt 0 ]
+ mysql -u root -e 'create database my_wp_db;'
ERROR 2002 (HY000): Can't connect to local server through socket '/var/run/mysql/mysql.sock' (2)
...

Don't start services with uci-defaults, it is not designed for this task as it breaks startup order.

1 Like