【问题标题】:Executing a script on startup using BeagleBone Black使用 BeagleBone Black 在启动时执行脚本
【发布时间】:2015-03-04 12:37:08
【问题描述】:

我有一个a.out,我想在我的BeagleBone 启动时运行它。它实际上是一个套接字服务器,我想在 BeagleBone 通电后立即启动它。我试图把它放在/etc/init.d,但它没有帮助。我编写了一个 shell 脚本来运行这个可执行文件,但即使这样也没有帮助。

如何让脚本在启动后立即运行?

【问题讨论】:

  • 欢迎来到 Stack Overflow!我已经改写了你的问题,这样很容易找出来,我已经链接到董事会,以防万一有人不熟悉它。
  • 您在 BBB 上使用的 Debian 发行版(和版本)到底是什么?我在问,因为您首先需要弄清楚的是哪个init system 用于您的分发。据我记得,一些版本的 BBB 带有systemd。如果是你的情况——你需要弄清楚如何为 systemd 创建初始化脚本,或者用 sysv-init 替换它。另请参阅this question
  • 我找到了一个解决方案,我在 /lib/systemd 中编写了一个服务来在开机时运行我的 a.out 文件,它工作正常。无论如何,感谢山姆的帮助

标签: debian startup beagleboneblack


【解决方案1】:

我按照 7 个步骤创建了一个服务,但它对我不起作用,然后我将我的 shellscript 命令放在 /etc/rc.local 中运行我的程序,它就起作用了。

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

cd /home/my_program_directory
/home/my_program_directory/my_executable

exit 0

【讨论】:

    【解决方案2】:

    我花了很长时间才弄清楚这一点,但经过大量研究,我终于找到了我想要的东西。

    1. 编译所需的代码。

    2. 创建一个 bash 脚本,它将在启动/启动时启动代码

      cd /usr/bin/
      

      输入nano scriptname.sh

      #!/bin/bash
      /home/root/name_of_compiled_code
      

      保存并授予执行权限

      chmod u+x /usr/bin/scriptname.sh
      
    3. 创建服务

      nano /lib/systemd/scriptname.service
      
    4. 根据需要编辑上述文件以调用不同的功能,如网络。仅当代码需要该特定服务时才启用这些。禁用不需要的以减少启动时间。

      [Unit]
      Description=description of code
      After=syslog.target network.target
      [Service]
      Type=simple
      ExecStart=/usr/bin/scriptname.sh
      [Install]
      WantedBy=multi-user.target
      
    5. 创建一个符号链接,让设备知道服务的位置。

      cd /etc/systemd/system/
      ln /lib/systemd/scriptname.service scriptname.service
      
    6. 使systemd重新加载配置文件,立即启动服务(帮助查看服务是否正常运行)并启用命令行中指定的单元文件。

      systemctl daemon-reload
      systemctl start scriptname.service
      systemctl enable scriptname.service
      
    7. 立即重新启动 BBB 以查看它是否按预期运行。

      reboot
      

    (所有功劳归http://mybeagleboneblackfindings.blogspot.com/2013/10/running-script-on-beaglebone-black-boot.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-14
      • 1970-01-01
      • 1970-01-01
      • 2016-06-23
      • 2017-02-26
      • 1970-01-01
      • 1970-01-01
      • 2016-12-20
      相关资源
      最近更新 更多