解决开机自动调用脚本失败的问题

系统版本

# cat /etc/redhat-release
CentOS release 6.5 (Final)

问题情景:云主机上部署的是多实例mysql数据库,希望实现开机数据库服务自启动。系统在启动所有的服务后会执行/etc/rc.d/rc.local 中的命令,如下操作

# cat /etc/rc.d/rc.local 
#!/bin/sh
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

/bin/sh  /tmp/script/tools/st_mysql

#调用的脚本内容
# cat st_mysql 
# 启动mysql服务
ls -l /etc/mysql/|awk '{print $9}'|cut -d'.' -f1|uniq|xargs -i /tmp/mysql/bin/mysqld_multi --defaults-extra-file=/etc/mysql/{}.cnf --no-log start {}

但是重启主机后,发现mysql服务并未启动,在系统启动日志/var/log/boot.log 中也未发现相关信息

解决过程

对脚本增加可执行权限

输出调用脚本的过程到日志文件,如:/bin/sh -x /tmp/script/tools/st_mysql>/tmp/st_mysql.log

然后重新测试发现日志文件中的输出内容为

# vim /etc/rc.d/rc.local 

WARNING: my_print_defaults command not found.
Please make sure you have this command available and
in your path. The command is available from the latest
MySQL distribution.

这是未设置mysql环境变量引发的,系统在执行rc.local文件后才会加载环境变量,所以需要将rc.local的内容改为

# cat /etc/rc.d/rc.local 
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

source /root/.bash_profile

/bin/sh -x /tmp/script/tools/st_mysql>/tmp/st_mysql.log

至此,解决问题

转载于:https://www.cnblogs.com/Bccd/p/6285243.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值