【问题标题】:Automatic launch of a program as root on debian 10 boot在 debian 10 启动时以 root 身份自动启动程序
【发布时间】:2021-02-27 15:10:17
【问题描述】:

在装有 debian 10 的 PC 上,我开发了一个 C 程序(我自己的 snmp 代理),可以在以下位置找到:

/home/myuser/myapp/myprogram

我需要它在每次 PC 启动时自动启动,以 root 身份运行。

为此,我遵循以下步骤:

  1. 我使用以下内容创建文件“/etc/systemd/system/rc-local.service”:
[Unit]
Description=/etc/rc.local
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
  1. 我使用以下内容创建文件“/etc/rc.local”:
#!/bin/sh -e

/home/myuser/myapp/myprogram

exit 0
  1. 将权限设置为 rc.local:
sudo chmod +x /etc/rc.local
  1. 启用服务以在引导期间启动
sudo systemctl enable rc-local
  1. 当我启动服务时:
sudo systemctl start rc-local

我在屏幕上看到这些错误:

Job for rc-local.service failed because the control process exited with error code.
See "systemctl status rc-local.service" and "journalctl -xe" for details.
  1. 当我检查服务的状态时,它显示错误:
systemctl status rc-local

● rc-local.service - /etc/rc.local
   Loaded: loaded (/etc/systemd/system/rc-local.service; enabled; vendor preset: enabled)
  Drop-In: /usr/lib/systemd/system/rc-local.service.d
           └─debian.conf
   Active: failed (Result: exit-code) since Mon 2020-11-16 12:29:59 CET; 3min 36s ago
  Process: 1686 ExecStart=/etc/rc.local start (code=exited, status=139)

Nov 16 12:29:59 i66vm-test systemd[1]: Starting /etc/rc.local...
Nov 16 12:29:59 i66vm-test rc.local[1686]: Modules initializing
Nov 16 12:29:59 i66vm-test rc.local[1686]: duplicate registration: MIB modules trapInfo and trapInf
Nov 16 12:29:59 i66vm-test rc.local[1686]: Segmentation fault
Nov 16 12:29:59 i66vm-test systemd[1]: rc-local.service: Control process exited, code=exited, status=139
Nov 16 12:29:59 i66vm-test systemd[1]: rc-local.service: Failed with result 'exit-code'.
Nov 16 12:29:59 i66vm-test systemd[1]: Failed to start /etc/rc.local.

我不明白为什么它不启动,因为如果我手动启动程序,它会启动并正常工作,即使它显示广告:

duplicate registration: MIB modules trapInfo and trapInfo (oid .1.3.6.1.4.1.1234.1.1.2.1).

感谢任何帮助。

有一种更好的方法可以在计算机启动期间在 debian 10 中自动启动程序, 考虑到它必须以 root 身份运行?

【问题讨论】:

    标签: debian snmp boot


    【解决方案1】:

    正如您要求的另一种方式,是的,有几种方式。最简单的方法是在根处输入一行crontab -e

    # m h  dom mon dow   command
    @reboot /home/myuser/myapp/myprogram
    

    【讨论】:

      猜你喜欢
      • 2013-06-09
      • 2020-08-18
      • 2016-05-08
      • 2013-11-23
      • 2014-10-12
      • 1970-01-01
      • 2022-10-16
      • 2015-06-18
      • 2013-10-14
      相关资源
      最近更新 更多