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
1 Like

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
2 Likes

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

Hi, I think you have a typo under [Service] on the following line of your post:

I believe the proper syntax to be:

ExecStartPre=+chown pi.pi /tmp/mycroft

@mshelby - thanks for the reply - Iā€™ve had the startup script working for a while. I no longer have that line as /tmp/mycroft is owned by pi and it does not change. Hereā€™s what I have now for reference:

[Unit]
Description=Mycroft AI
After=pulseaudio.service

[Service]
User=pi
WorkingDirectory=/home/pi/
ExecStart=/home/pi/mycroft-core/bin/mycroft-start all
ExecStop=/home/pi/mycroft-core/bin/mycroft-stop
Type=forking
Restart=no
Environment="XDG_RUNTIME_DIR=/run/user/500"

[Install]
WantedBy=multi-user.target
-Mike M
1 Like