Auto-Restart the PicarX script with systemctl

Hi Andy,

I’m suffering through the same problem of trying to run an app with systemd that uses picarx.py.
It works fine from the CLI. Otherwise I’m getting the errno[6] :frowning:

You said you got it mostly working. I’ve tried the fix of replacing getlogin and I moved the conf file to the project directory. Still no luck. Would you mind divulging your solution in a bit more detail?

Thanks

Will need some time to get into the Pi (built it for my grandson and it’s at his house). I did modify sunfounders picarx.py in the init changing the line:
self.config_file = fileDB(config, 777,os.getlogin())
with:
self.config_fil = fileDB(config,777,getpass.getuser())

b/c that call is obe.
As far as starting it as a service I’ll have to keep looking but did get it to work.

Thanks. It’s definitely the picarx.py that’s the culprit. I think it’s not getting access to robot_hat under systemd.

Actually it seems to work now. Perhaps the os.getlogin() is all that’s needed.
I probably made too many changes so I reverted and just changed the os.getlogin().
I’m good now.
Cheers

Great to hear; as I remember without making that change the code picks up the wrong configuration file:

    #print(f'getpass.getuser()={getpass.getuser()} os.getlogin()={os.getlogin()}')
    print(f'getpass.getuser()={getpass.getuser()}')
    if getpass.getuser() == 'root': 
        self.config = '/opt/picar-x/picar-x.conf'
    print(f'FILE self.config: {self.config}')        # --------- config_flie ---------
    #self.config_flie = fileDB(config, 777, os.getlogin())
    self.config_flie = fileDB(config, 777, getpass.getuser())    

I ended up debugging with VScode but had to set a switch for the debugger to step through the picarx code

1 Like