在debian 10引导上以root用户身份自动启动程序

在debian 10引导上以root用户身份自动启动程序,debian,snmp,boot,Debian,Snmp,Boot,在装有debian 10的PC上,我开发了一个C程序(我自己的snmp代理),可在以下位置找到: /home/myuser/myapp/myprogram 我需要它在每次电脑启动时自动启动,以root用户身份运行 为此,我遵循以下步骤: 我使用以下内容创建文件“/etc/systemd/system/rc local.service”: 我使用以下内容创建文件“/etc/rc.local”: 将权限设置为rc.local: 使服务在引导期间启动 当我启动服务时: 我在屏幕上看到以下错误: Jo

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

/home/myuser/myapp/myprogram
我需要它在每次电脑启动时自动启动,以root用户身份运行

为此,我遵循以下步骤:

  • 我使用以下内容创建文件“/etc/systemd/system/rc local.service”:
  • 我使用以下内容创建文件“/etc/rc.local”:
  • 将权限设置为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.
    
  • 当我检查服务的状态时,它显示一个错误:
  • 我不明白为什么它没有启动,因为如果我手动启动该程序,它确实启动并正常工作,即使它显示广告:

    duplicate registration: MIB modules trapInfo and trapInfo (oid .1.3.6.1.4.1.1234.1.1.2.1).
    
    感谢您的帮助

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

    当您询问其他方法时,是的,有几种方法。最简单的方法是在根
    crontab-e

    # m h  dom mon dow   command
    @reboot /home/myuser/myapp/myprogram
    
    sudo systemctl enable rc-local
    
    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.
    
    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).
    
    # m h  dom mon dow   command
    @reboot /home/myuser/myapp/myprogram