running a command on pi boot after IP is assigned
在Raspberry Pi 4B 上,試過有效。
You can make a systemd service for your program and enable it via systemctl.
First, create a file
/etc/systemd/system/<name>.service
on the Pi. (Be sure to replace <name>
with a actual service name.)sudo touch /etc/systemd/system/<name>.service
Write in this file with your favorite text editor (nano, etc):
[Unit]
Description=blah service
After=network.target
[Service]
Type=oneshot
User=pi
ExecStart=yourcommand
[Install]
WantedBy=multi-user.target
Replace yourcommand with the command you want to run. Then save the file and close the text editor.
Next, reload the daemon to make systemd recognize your service:
sudo systemctl daemon-reload
Then, we can make it run on boot now:
sudo systemctl enable <name>
(Again, make sure to replace
<name>
with the name of your service.)
Enjoy your start-on-boot command!
EDIT: didn't realize this post was that old actually. but anyways, either mark a answer as correct or state your solution in a answer and mark that so it doesn't show up on the front page
沒有留言:
張貼留言