使用 BeagleBone Black 在启动时执行脚本 [英] Executing a script on startup using BeagleBone Black

查看:38
本文介绍了使用 BeagleBone Black 在启动时执行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an a.out which I want to run when my BeagleBone boots up. It is actually a socket server which I want to start as soon as the BeagleBone powers up. I tried to put this in /etc/init.d, but it didn't help. I wrote a shell script to run this executable but even that did not help.

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

What can I do to make a script run as soon as it boots up?

推荐答案

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

It took me quite some time to figure this out, but with lots of research, I finally found what I was looking for.

  1. 编译所需的代码.

  1. Compile the required code.

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

Create a bash script that will launch the code at boot/ startup

cd /usr/bin/

输入nano scriptname.sh

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

保存并授予执行权限

chmod u+x /usr/bin/scriptname.sh

  • 创建服务

  • Create the service

    nano /lib/systemd/scriptname.service
    

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

  • Edit the above file as necessary to invoke the different functionalities like network. Enable these only if the code needs that particular service. Disable unwanted ones to decrease boot time.

    [Unit]
    Description=description of code
    After=syslog.target network.target
    [Service]
    Type=simple
    ExecStart=/usr/bin/scriptname.sh
    [Install]
    WantedBy=multi-user.target
    

  • 创建一个符号链接,让设备知道服务的位置.

  • Create a symbolic link to let the device know the location of the service.

    cd /etc/systemd/system/
    ln /lib/systemd/scriptname.service scriptname.service
    

  • 使systemd重新加载配置文件,立即启动服务(帮助查看服务是否正常运行)并启用命令行中指定的单元文件.

  • Make systemd reload the configuration file, start the service immediately (helps to see if the service is functioning properly) and enable the unit files specified in the command line.

    systemctl daemon-reload
    systemctl start scriptname.service
    systemctl enable scriptname.service
    

  • 立即重新启动 BBB 以查看它是否按预期运行.

  • Restart BBB immediately to see if it runs as intended.

    reboot
    

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

    这篇关于使用 BeagleBone Black 在启动时执行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆