how-can-i-run-a-program-as-a-root-user-when-my-ubuntu-15-04-machine-starts-up

http://unix.stackexchange.com/questions/202698/how-can-i-run-a-program-as-a-root-user-when-my-ubuntu-15-04-machine-starts-up



You're using Ubuntu version 15. You have systemd. /etc/rc.local is at best a backwards compatibility mechanism in systemd. And as shown by the mess in the AskUbuntu question hyperlinked below, using it can go horribly wrong. So make a proper systemd service unit.

You are creating a local, non-system non-package, service unit, so the unit file will be in /etc/systemd/system/ which is where that type of units go.
Let us call it /etc/systemd/system/myscript.service. It contains:

[Unit]
Description=user2580's script
Documentation=http://unix.stackexchange.com/questions/202698/

[Service]
Type=simple
ExecStart=/usr/local/bin/myscript

[Install]
WantedBy=multi-user.target
If your script forks "in order to dæmonize" then stop it from doing so. That's completely unnecessary.

*Run systemctl preset myscript.service (as the superuser) to have it start automaticallydoes not execute your script in a context where it will be able to talk to an X server. It could be run before an X server is even started up. But you don't mention any requirement for being an X client, nor for other complexities that bite novices like a HOME environment variable. And those are subjects for other questions, in any case. So I'll leave it at that.
, nor for other complexities that bite novices like a HOME environment variable. And those are subjects for other questions, in any case. So I'll leave it at that.