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

查看:150
本文介绍了使用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天全站免登陆