How to launch your flutterpi app at startup
What is the best way to launch your app at startup and have keyboard support & touch support (basicly everything)
This is what I followed. And it works. but this keeps a terminal open where the keyboard types
Launch script
Create a script here ~/projects/launch_my_app.sh
#!/bin/bash
flutter-pi --release projects/my_app
Boot service
Here's a comprehensive setup guide for creating a systemd service that will automatically launch your Flutter app on a Raspberry Pi using your custom startup script.
1. Create the Systemd Service File
Open a terminal on your Raspberry Pi and create a new service file for your app:
sudo nano /etc/systemd/system/my_app.service
2. Configure the Service File
In the editor, paste the following configuration. Adjust the paths and usernames as necessary.
[Unit]
Description=Launch Flutter App
After=network.target
[Service]
ExecStart=/home/pi/projects/launch_my_app.sh
Restart=on-failure
User=pi
Environment=DISPLAY=:0
[Install]
WantedBy=multi-user.target
- Description: Provides a brief description of the service.
- After=network.target: Ensures the service waits until the network is available (if required).
- ExecStart: Specifies the path to your custom launch script (
launch_my_app.sh). - Restart=failure: Restarts the service if it fails (if it stops it is probably because we need to access the CLI).
- User: Sets the user account to run the service. Replace
piwith your actual username. - Environment=DISPLAY=:0: Sets the display variable, necessary for GUI applications. Adjust
:0if your setup uses a different display.
3. Enable the Service to Start on Boot
After configuring the service file, save and close the editor (Ctrl+X, then Y, then Enter). Then, enable the service to run on boot:
sudo systemctl enable my_app.service
4. Test the Service
To test that everything is set up correctly, start the service manually:
sudo systemctl start my_app.service
You can check the status to verify that it’s running without errors:
systemctl status my_app.service
5. Reboot to Confirm Auto-Start
To ensure the service starts on boot, reboot your Raspberry Pi:
sudo reboot
Once the system reboots, you can confirm that your app is running by checking the service status again:
systemctl status my_app.service
This setup ensures your Flutter app will start automatically each time the Raspberry Pi reboots, using your launch_my_app.sh script for custom setup.
6. Stop the service
sudo systemctl stop my_app.service
The problem
This works, only the keyboard is still typing in the terminal that is still open behind the flutter app
Currently I use cron job to run program on boot, all functionalities (also touch and keyboard) are working like a charm
sudo crontab -e
then in the bottom of the text editor (you can use vim, nano, etc) add this line:
@reboot /home/[your-username]/projects/launch_my_app.sh >> /home/[your-username]/projects/launch_my_app.log
*note: change [your-username] with your actual username
Then save the cron settings
@effmuhammad cool! I have a functionality "restart app" or "restart on crash" how would you do that with a cronjob? The service works great because you can say restart of fail so you get it out of the box.
@vanlooverenkoen as I know the cronjob not support it by default, but i found a convincing solution in stackexchange. I will check it later
The approach I've found to work (so far) is to override the command run by the standard getty on the first tty:
cat <<__EOF >/etc/systemd/system/[email protected]/override.conf
[Service]
ExecStart=
ExecStart=/home/pi/projects/launch_my_app.sh
__EOF
This stops the standard login getty process claiming tty1. Note: the empty ExecStart= line is required, otherwise you add a command rather than replacing the getty.
It's early days in testing, but this is the approach I'm using for my Boat Instrument.
As a quick test, you could install the Boat Instrument from my Debian PPA and test if your touchscreen and keyboard work.