FAQs
Contents
Some users using the BB-400 will want to use their own developed software to do as they want, whether it’s processing data to a cloud service or reading the inputs and triggering outputs.
This FAQ describes the process of setting up your software to run automatically on startup on a BB-400, to avoid ever needing to log in and manually do it every time you reboot the device.
There are several different ways of doing this, but this guide will show how to create a service to run something at boot.
Software, Equipment & Requirements
Software/Equipment | Details |
---|---|
Brainboxes BB-400 IoT Neuron Edge | |
SSH Connection | Terminal access to the BB-400 |
Procedure
Create Service
Firstly, create a new file inside the systemd folder, with the extension .example, for example:
$ sudo nano /etc/systemd/system/example.service
An example of what can be inside is provided below, with some explanations in the comments.
[Unit]
Description=My Example Service
# You can put multiple 'After=' targets
## This one runs your service after a network connection has been established
After=network.target
## These two run after the Linux filesystem has properly loaded
After=remote-fs.target
After=rc-local.service
[Service]
Type=simple
WorkingDirectory=/home/example
ExecStart=/home/example/example.sh
Restart=always
# The install section is needed to use `systemctl enable` to start on boot
# For system level services, use `multi-user.target`
[Install]
WantedBy=multi-user.target
Just a small description of some options available for these key parameters in the service file:
Type=...
Configures the process start-up type for this service unit.simple
: The service manager will consider the unit started immediately after the main service has been forked off. It is expected that the process configured withExecStart=
is the main process of the service.exec
: Similar to simple; but the service manager will consider the unit started immediately after the main binary has been executed.forking
: If it is expected that the process configured withExecStart=
will callfork()
as part of its start-up.oneshot
: Similar to simple; however, the service manager will consider the unit up after the main process exits.idle
: Similar to simple; however, actual execution of the service program is delayed until all active jobs are dispatched.
WorkingDirectory=...
- This will be the location of the executed file
ExecStart=...
- This will be the full path of the executed file
Restart=...
Configures whether the service shall be restarted when the service process exits, is killed, or a timeout is reached.
Restart Settings/Exit Causes | no |
always |
on-success |
on-failure |
on-abnormal |
on-abort |
on-watchdog |
---|---|---|---|---|---|---|---|
Clean exit code or signal | ✔️ | ✔️ | |||||
Unclean exit code | ✔️ | ✔️ | |||||
Unclean signal | ✔️ | ✔️ | ✔️ | ✔️ | |||
Timeout | ✔️ | ✔️ | ✔️ | ||||
Watchdog | ✔️ | ✔️ | ✔️ | ✔️ |
This is a very simple example of how you can create a service file.
There are a lot more configuration settings and parameters you can implement to get the service to work how you want it to. You can add a Timeout
if you have some small downtime or ExecStopPost
to add additional scripts to execute if your application ends or closes.
If you need more, you can read all the service options by running man systemd.service
or get the full manual here
Enable Service
After your software has been set in place and the .service file has been created, you’re ready to enable the service for it to run at boot.
$ sudo systemctl enable example.service
That’s all to it!
The next time you reboot your system, the service will execute the parameters you have set inside the .service file.
Problems & Issues
Some common issues you could run into during this process are listed below, however, different custom software can introduce its own specific issues. When a specific error is encountered that is not listed below, an internet search for the exact error will probably solve your issue quickly.
Alternatively contact brainboxes technical support for errors related to your BB-400 at: [email protected]
Debug the Target
A script file called example.sh
will be used as an example. It has the following:
#!/bin/bash
echo "Hello World!"
exit 0
Make sure that the file (the ExecStart=
target) has executable permissions.
$ sudo chmod +x example.sh
Check that the application is successfully executing outside the service.
$ sudo ./example.sh
"Hello World!"
After you have confirmed it’s working, try executing the service file from the terminal through systemctl.
$ sudo systemctl start example.service
"Hello World!"
If it continues to fail, please check the status/log files.
View Status/Logs
These commands will give you the status of the service, and output additional info in journalctl
# See if running, uptime, view latest logs
$ sudo systemctl status example.service
# Show logs for specific service
$ sudo journalctl -u example.service