-
Notifications
You must be signed in to change notification settings - Fork 130
Raspberry Pi autostart
This is based on the technique described here
- create a
misterhouse.service
file for your service, in a locaion of your choice e.g./home/pi/mh/misterhouse.service
for example:
[Unit]
Description=Misterhouse
Requires=rpcbind.service
After=rpcbind.service
[Service]
Environment="mh_params=/home/pi/mh/mh.private.ini"
Type=simple
ExecStart=/opt/misterhouse/mh.sh
Restart=on-abort
[Install]
WantedBy=multi-user.target
Where mh.private.ini
is your private mh.ini
file
Copy this file into /etc/systemd/system
as root, for example:
sudo cp /home/pi/mh/misterhouse.service /etc/systemd/system/misterhouse.service
Next create the shell command to actually run MisterHouse /opt/misterhouse/mh.sh
in this example;
#!/bin/sh
# this is the script that starts MisterHouse on startup, it lives in /opt/misterhouse
# set up environmnt
export mh_parms=/home/pi/mh/mh.private.ini
# Save the old log file in case there was a crash
cp -f /opt/misterhouse/mh.log /opt/misterhouse/mh.old.log
# The next line starts mh
/home/pi/mh/mh/bin/mh > /opt/misterhouse/mh.log 2>&1
Check that you can write to the mh.log file
sudo touch /opt/misterhouse/mh.log
sudo chown pi:pi /opt/misterhouse/mh.log
touch /opt/misterhouse/mh.log
Make /opt/misterhouse/mh.sh
executable and check that it starts MisterHouse correctly for your environment;
sudo chmod +x /opt/misterhouse/mh.sh
/opt/misterhouse/mh.sh
Now check that the systemctl can start and stop your new service
sudo systemctl start misterhouse.service
sudo systemctl stop misterhouse.service
Now enable it to autostart
sudo systemctl enable misterhouse.service
- Create a directory called
/home/pi/.config/autostart
- Create a file called
/home/pi/.config/autostart/mh.desktop</span>
- Edit
mh.desktop
to contain the following contents:
[Desktop Entry]
Type=Application
Exec=lxterminal --command 'bash -c "sudo /home/pi/MisterHouse/mhl; exec bash"'
-
The Exec line above is more complicated than I would like but it seems to be the only way to get MisterHouse to start in an lxterminal window that doesn't close when MisterHouse is quit or terminated with ctrl-C. This is accomplished by running 'exec bash' as a second command after 'mhl' exits. If you don't want the lxterminal window to remain open if mhl exits, you can use
Exec=lxterminal --command 'sudo /home/pi/MisterHouse/mhl
instead. -
Run
sudo reboot
from a terminal to restart the Pi. -
If MisterHuse doesn't start after reboot, check the contents of the
/home/pi/.xsession-errors
file for clues.