This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] 如何在启动 Linux 系统时将可执行程序设置为自动以 root 用户身份启动?

Guru**** 2539130 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/processors-group/processors/f/processors-forum/736796/how-can-i-set-an-executable-program-start-automatically-in-root-when-starting-the-linux-system

器件型号:AM5728

工具/软件:Linux

我在 C/C++中编译了一个可执行程序、并且希望在启动 Linux 系统时自动以根启动程序。但我发现登录操作是在自动启动程序之后进行的。如何在 root 帐户中自动设置程序启动。systemd mechnism 能否实现这一点?

感谢你的任何帮助。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    您好、user5032711、

    请参阅链接的教程、了解如何在引导时运行脚本:
    debian-administration.org/.../Making_scripts_run_at_boot_time_with_Debian
    然后您的脚本可以启动可执行程序。

    BR
    Tsvetolin Shulev
  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    user5032711、

    我想补充一些澄清。

    让您的可执行程序命名为"YourApp"。

    例如,您应该在文件夹/etc/systemd/system 中创建 名为“testscript.service"”的服务。

    [unit]
    Description=我的测试脚本
    after = network.target
    
    [Service]
    ExecStart=/path_TO_YourApp/YourApp
    Type=OneShot
    StandardOutput=kmsg+console
    
    [安装]
    Wanteby=multi-user.target 

    然后执行以下命令:

    systemctl 启用 testscript.service
    systemctl 守护程序重新加载
    

    重新启动设备应执行 YourApp。

    BR

    Tsvetolin Shulev