Mycroft Community Forum

Mycroft will not start at boot time

Hi,

I am trying to get mycroft to start on Raspberry Pi OS (not pycroft) as a service as defined in the documentation. Here is the sytsemd script:

$ cat /etc/systemd/system/mycroft.service
[Unit]
Description=Mycroft AI
After=pulseaudio.service network-online.target
Wants=network-online.target

[Service]
User=pi
WorkingDirectory=/home/pi/
# ExecStartPre=/bin/sleep 30
ExecStart=/home/pi/mycroft-core/bin/mycroft-start all
ExecStop=/home/pi/mycroft-core/bin/mycroft-stop
Type=simple
Restart=no

[Install]
WantedBy=multi-user.target

Before boot, I look at the /tmp/mycroft/ directory and see it is owned by pi:

$ ls -ld /tmp/mycroft
drwxr-xr-x 3 pi pi 4096 Jun  5 13:44 /tmp/mycroft

I reboot the system:

$ reboot
...

The Raspi goes down and comes back up and mycroft should be running, but it is not. I login and see that the ownership of /tmp/mycroft/ has been changed to root:

$ ls -ld /tmp/mycroft
drwxr-xr-x 2 root root 4096 Jun  5 14:38 /tmp/mycroft
$ grep Errno /var/log/mycroft/bus.log
PermissionError: [Errno 13] Permission denied: '/tmp/mycroft/service.pid'

It seems the startup scripts cannot create the file with the process ID. How is the ownership of /tmp/mycroft/ being changed from pi to root?

Any help will be appreciated.

-Mike M

If you disable your Mycroft systemd service - set the owner as pi and reboot, does it change back to root?
i.e. is this being caused by that systemd service or is the directory being modified during boot by the system before Mycroft even launches?

gez, thanks for the quick reply.
Yes, the ownership does change back to root even when mycroft is disabled.
Strange… I’m stumped.

-Mike M

Probably the tmpfiles services of systemd that reconfigures everything at boot.
https://www.freedesktop.org/software/systemd/man/tmpfiles.d.html

/tmp might be a tmpfs, so doesn’t survive reboots

Thanks j1nx - so which mycroft code writes the process ID to /tmp/mycroft/? Could that be changed to /home/pi?

-Mike M

I don’t know, but PID files are not written by Mycroft but the underlying system.

Ussually they are written to /var/run or /run

Worth a try is to change the Type=simple to Type=forking

Perhaps that works for you. What distribution are you running btw?

1 Like

J1nx,

SUCCESS!!!

Finally. Changing to Type=forking and adding an ExecPreStart line (and yes, the extra ‘+’ is needed - it’s like sudo) enable mycroft to run at boot time. Here’s the complete systemd file:

pi@raspberrypi:~$ cat /etc/systemd/system/mycroft.service
[Unit]
Description=Mycroft AI
After=pulseaudio.service network-online.target
Wants=network-online.target

[Service]
User=pi
ExecPreStart=+chown pi.pi /tmp/mycroft
WorkingDirectory=/home/pi/
ExecStart=/home/pi/mycroft-core/bin/mycroft-start all
ExecStop=/home/pi/mycroft-core/bin/mycroft-stop
Type=forking
Restart=no

[Install]
WantedBy=multi-user.target

Somebody might want to update the example on:
https://mycroft-ai.gitbook.io/docs/using-mycroft-ai/get-mycroft/linux#start-mycroft-on-boot

The distro is Raspberry Pi OS (aka Raspbian). I want the box to also be a general purpose computer as RasPis have just about enough horsepower these days …

Thanks for everyone’s help.

- Mike M
1 Like

Ok, great that you got it working…

Couple of things, though;

Strange that the error was there with “Type=simple” as systemd doesn’t write PID files with that type ?!?!? Anyhow, sometimes you just take the solution, even if you don’t understand why.

The proper fix for your ExecPreStart solution would be;
As root create a file /etc/tmpfiles.d/mycroft.conf with the below content;

d /tmp/mycroft 755 mycroft mycroft

At boot systemd as root user will takecare of creatin the mycroft folder there with the right permissions