服务器配置开机自启动rc.local

作者 时间
star 2019-12-16

环境

国产操作系统: 凝思磐石4.2

操作

  1. 配置软连接(该系统该版本没有该软连接,故需配置,如果已有则不用配置):
    ln -s /etc/rc.d/rc.local /etc/rc.local
  2. 赋予启动脚本执行权限:
    chmod u+x /etc/rc.d/rc.local /etc/rc.local
  3. 在/etc/rc.local中添加启动命令:
    例:
#!/bin/bash
#
# 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/su - dcloud -l -c "/home/dcloud/opt/elasticsearch-6.1.2/bin/elasticsearch -d" >/tmp/es.log 2>&1

exit 0

命令说明:

  1. ·/bin/su - dcloud -l -c· :指定使用dcloud用户执行启动命令,软件最好不要使用root启动,建议使用固定的用户启动,避免出现文件权限问题。
  2. ·>/tmp/es.log 2>&1·: 这个日志是为了调试开机启动脚本的,当脚本配置不对时,可以从指定的配置文件中查看日志。
  3. 所有的脚本都应该在exit 0 前面
  4. rc.local方式配置开机自启动命令无法加入依赖,但是rc.local中的命令是顺序执行的,可以按照依赖的顺序,配置命令。

你可能感兴趣的:(服务器配置开机自启动rc.local)