launch application at boot in root environment, then monitor and if closes or crashes relaunch

by Michael   Last Updated September 21, 2018 13:01 PM

I have a question regarding how i can launch an application, written in python, as soon as boot has been completed. This application needs to run with full permissions, so that passwords are not required, as there are two commands that it runs with sudo.

I also need it to relaunch the application with the same permissions if the application shutdown.

I've done similar things, but never all together. For instance, to launch at boot. I would throw a short script that calls the application I want in another directory, in the init.d directory. Then by doing "update-rc.d app defaults", it will auto launch as part of the startup scripts for Ubuntu

for relaunching a program if it crashes another simple script

from subprocess import Popen
import sys

filename = sys.argv[1]
while True:
    print("\nStarting " + filename)
    p = Popen("python " + filename, shell=True)

gets the job done. I can insert the application name at filename so I don't have to supply it as part of the arguments when I call it.

my main issue is the application I'm running needs to run in root environment, autolaunch at boot, and relaunch if its shutdown.

Any suggestions?

Related Questions

Kali Linux setoolkit error message

Updated March 01, 2017 10:01 AM

How to disable a keyboard key on startup in Linux?

Updated January 23, 2018 13:01 PM