rc.local开机执行用Go写的应用失败

/etc/rc.d/rc.local和/etc/rc.local都赋予了执行权限
/etc/rc.d/rc.local和/etc/rc.local配置如下

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
/usr/opt/nginx/sbin/nginx
/usr/opt/etlive-page-01/server
/usr/opt/etlive-page-02/server
service iptables start 

server是在这台linux上面编译go文件输出的可执行文件。手动执行可以执行
执行效果

[root@Nginx02 etlive-page-01]# pwd
/usr/opt/etlive-page-01
[root@Nginx02 etlive-page-01]# ./server
2018/04/04 18:01:59 [I] http server Running on http://:8080
阅读 3.2k
2 个回答

试试这样

#!/bin/bash
touch /var/lock/subsys/local
/usr/opt/nginx/sbin/nginx &
/usr/opt/etlive-page-01/server &
/usr/opt/etlive-page-02/server &
service iptables start 

除了楼上说的后台执行试试看。
还有你要确认下直接/usr/opt/etlive-page-01/server 运行是否可以?检查下程序里是否有写死调用相对目录(当前所在目录)的地方

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题