title: Automatic launch of a program as root on debian 10 boot
body: <p>On a PC with debian 10 I have developed a C program (my own snmp agent) that can be found in:</p>
  <pre><code>/home/myuser/myapp/myprogram
  </code></pre>
  <p>And I need it to start automatically every time the PC boots, running as root.</p>
  <p>To do this I follow the following steps:</p>
  <ol>
  <li>I create the file &quot;/etc/systemd/system/rc-local.service&quot; with this content:</li>
  </ol>
  <pre><code>[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
  </code></pre>
  <ol start="2">
  <li>I create the file &quot;/etc/rc.local&quot; with this content:</li>
  </ol>
  <pre><code>#!/bin/sh -e
  
  /home/myuser/myapp/myprogram
  
  exit 0
  </code></pre>
  <ol start="3">
  <li>Set the permissions to rc.local:</li>
  </ol>
  <pre><code>sudo chmod +x /etc/rc.local
  </code></pre>
  <ol start="4">
  <li>Enable the service to start during boot</li>
  </ol>
  <pre><code>sudo systemctl enable rc-local
  </code></pre>
  <ol start="5">
  <li>When I start the service:</li>
  </ol>
  <pre><code>sudo systemctl start rc-local
  </code></pre>
  <p>I get these errors on the screen:</p>
  <pre><code>Job for rc-local.service failed because the control process exited with error code.
  See &quot;systemctl status rc-local.service&quot; and &quot;journalctl -xe&quot; for details.
  </code></pre>
  <ol start="6">
  <li>When I check the status of the service, it shows an error:</li>
  </ol>
  <pre><code>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.
  </code></pre>
  <p>I do not understand why it does not start, since if I manually launch the program, it does start and works right, even if it shows the advertisement:</p>
  <pre><code>duplicate registration: MIB modules trapInfo and trapInfo (oid .1.3.6.1.4.1.1234.1.1.2.1).
  </code></pre>
  <p>Any help is appreciated.</p>
  <p>There is a better way to launch a program automatically in debian 10 during computer boot,
  considering that it must be run as root?</p>