服务器配置开机自启动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中的命令是顺序执行的,可以按照依赖的顺序,配置命令。
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容