Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to launch your flutterpi app at startup #461

Open
vanlooverenkoen opened this issue Nov 13, 2024 · 4 comments
Open

How to launch your flutterpi app at startup #461

vanlooverenkoen opened this issue Nov 13, 2024 · 4 comments

Comments

@vanlooverenkoen
Copy link

vanlooverenkoen commented Nov 13, 2024

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 pi with your actual username.
  • Environment=DISPLAY=:0: Sets the display variable, necessary for GUI applications. Adjust :0 if 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

@effmuhammad
Copy link

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

@vanlooverenkoen
Copy link
Author

@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.

@effmuhammad
Copy link

@vanlooverenkoen as I know the cronjob not support it by default, but i found a convincing solution in stackexchange. I will check it later

@philseeley
Copy link

The approach I've found to work (so far) it 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants