How to auto start on Rpi reboot ?
-
Hi
Do we have any instructions yet to follow for auto starting the MSR service on a Raspberry Pi after its rebooted?
Thanks
-
Assuming you are running on raspbian as a systemctl service, shouldn't enabling it do it?
sudo systemctl enable msr.service
Maybe you didn't create a service yet?
-
Yes its Raspbian.
I haven't created or done anything yet.
I am running MSR currently by using this command:
nohup ./app.sh &
Which I am running by using Putty on my Windows 10 laptop.
-
rafale77replied to cw-kid on Mar 15, 2021, 12:32 AM last edited by rafale77 Mar 14, 2021, 8:47 PM
If such is the case, create the service by creating the file
using putty logged in to your rpi:
sudo nano /etc/systemd/system/msr.service
paste in the following file content make sure the path to msr below is correct and change it if necessary:
[Unit] Description=Multi System Reactor After=network.target [Service] Type=simple ExecStart=nohup /home/user/msr/app.sh Restart=on-failure RestartSec=5s [Install] WantedBy=multi-user.target
Hit ctrl+o then ctrl+x to save and exit from nano.
reload the service daemon:
sudo systemctl daemon-reload
then enable the service
sudo systemctl enable msr
You can then start and top the service with the two commands:
sudo systemctl start msr sudo systemctl stop msr
-
In Nano it says [ Error writing /etc/systemd/system/msr.service: Permission denied ] when trying to save the file.
I then tried this instead:
sudo nano /etc/systemd/system/msr.service
And it saved and I now have a file called msr.service in that directory.
After this command
sudo systemctl enable msr
It says
Failed to enable unit: Invalid argument
-
-
This was the contents of the msr.service file.
I had to change the path slightly.
[Unit] Description=Multi System Reactor After=network.target [Service] Type=simple ExecStart=nohup /home/pi/Documents/reactor/app.sh Restart=on-failure RestartSec=5s [Install] WantedBy=multi-user.target
-
I would add
User=pi
at a minimum to the service section.I have concerns about the stop action. Investigating...
-
Thanks, I did miss the sudo for the nano command to create the file.
The path does look suspicious too in addition to @toggledbits input. There may be other specificities about raspbian I may be missing.
-
I made a mistake in the msr.service file. Corrected and now the "sudo systemctl enable msr" command runs with no error.
I then rebooted the Pi but some time later I still cannot load MSR in the browser.
-
This is the contents of the msr.service file now
[Unit] Description=Multi System Reactor After=network.target [Service] User=pi Type=simple ExecStart=nohup /home/pi/Documents/reactor/app.sh Restart=on-failure RestartSec=5s [Install] WantedBy=multi-user.target
-
can you show the error by posting the output of
sudo systemctl status msr
-
There are several things to indicate that the process is not ready for this at this point. Among them is that the nodejs installation done by the installer is local to the
pi
user. There are also issues with the home directory, and the search paths for modules and data relative to the current working directory vs the path of the application.Too soon. Not ready yet. Not going to fix it tonight. This is prelease software. It isn't mean to run like production software at this point.
-
Think I have it working now and MSR is auto starting after a reboot
I placed my msr.service file in this directory:
/home/pi/Documents/reactor
Using WinSCP, on the msr.service file properties, I made its Group and Owner to be pi rather than root.
This is the files contents:
[Unit] Description=Multi System Reactor After=network.target [Service] Type=simple ExecStart=nohup ./app.sh & WorkingDirectory=/home/pi/Documents/reactor Restart=on-failure RestartSec=5s [Install] WantedBy=multi-user.target
I then ran these commands in the terminal in Putty:
sudo systemctl enable /home/pi/Documents/reactor/msr.service
sudo systemctl start msr
And I can check its status with this command:
sudo systemctl status msr
It says its active and running.
If I reboot the Pi now after the reboot the MSR web page is then available and can be accessed.
-
Yeah, but running the shell script is not correct. You're basically having systemd do what the shell script is also doing (restarting when stopped), and it's going to cause problems. Your exec is also forking, so adding yet another layer of indirection that all but guarantees that systemd is going to be looking at the wrong process ID for what it thinks is a running Reactor. That could lead to problems stopping and restarting, and with the possible effect that an incorrect stop causes data loss.
-
Didn't think I'd set it up correctly More of a hack to get it auto started.
-
You're not far off, really, but the devilish details require some internal knowledge of how Reactor starts and organizes itself, and it's made a bit more complicated by the necessity to locate things "off shore" for docker containers and make sure that stays working as well. There's a bit of a balancing act there. As I'm sure you know well, features are not strictly governed by their ability to be implemented; they are also very much a function of what it takes to support them. I'd rather there be an "official" way that I know people use, because if ten people do it their own way, I'll have ten different ways I need to figure out any time there's a problem.
-
Can I ask what data one could loose in a power outage? I presume that any setup (rules/expressions) change is written to persistent files on "save"?
-
Right now, all data is written when modified, but that may not always be the case, and there's a high likelihood it will be user-configurable, even.
One of the things designed in is that MSR is "crappy-storage-ready". @rafale77 can tell you at length about the merits and woes of various storage technologies, and an SD card in a Raspberry Pi is no exception (in fact, probably both a good example and a dire warning). MSR has a storage architecture for its data that allows "pluggable" storage disciplines, so you could, for example, choose a cached-with-delayed-write-back mechanism to reduce wear, and you could choose that for everything, or just states, or states and logs, etc. So in that case, as the system shuts down, it is necessary for the cache to write back any "dirty" (modified but unsaved as yet) data, or the modifications would be lost.
That said, you should be thinking about getting your Pi off an SD card if that's what you're running, if you intend to run it full-time with MSR and depend on it. There are only two types of SD cards: those that have failed, and those that are about to. I have my Pi running on a cheap 2.5" SSD, and it's also a good bit faster, although there is some alchemy to getting that working, and while it's much better than it was, it involves some pretty magical incantations still today and can be a bit angst-inducing.
-
With the newer firmwares to the RPi it is fairly straight forward to use a SSD since it has native support now. Not that much alchemy anymore.
1/26