5

I'm using a Raspberry Pi 2 Model B running the latest Raspbian Stretch Lite 2018-11-13.

I built a program that communicates with a LoRa chip (SX1276) using SPI, gets some data from a temperature sensor and prints the temperature on the screen.

My program consists of only one executable (apart from wiringpi library).

I was searching for a tutorial to make my program a *.deb package. Using this tutorial I managed to build a lora.deb package.

When I installed my lora.deb package sudo dpkg -i lora.deb the executable just deployed in a directory.

How can I make that package automatically run the executable and also run it every time the system boots?

2
  • 5
    Check out systemd service files. If your deb package contains a service file, and you add a postinstall script to your package, you can bring up a service after install automatically and on boot. Commented Jan 12, 2019 at 20:48
  • 1
    See here here for guides to writing systemd unit files, which will be used by systemd (which handles startup) to start your service. Commented Jan 13, 2019 at 1:00

1 Answer 1

3

change '/usr/bin/something' to '/directory/path/to/deployed/executable' below:

$ cat /etc/systemd/system/something.service

[Unit]
Description = Something Service
After = network.target

[Service]
ExecStart = /usr/bin/something

[Install]
WantedBy = multi-user.target

$ systemctl daemon-reload
$ systemctl enable something
$ systemctl start something
2
  • Thank you very much! Reading through all those sites and tutorials I came up to the solution for the whole method. First of all I need to add a myapp.service into my *.deb package, then I'll have to write a postinst script that will copy the myapp.service into the proper path and enable the service. I'm not quite sure if instead of a copy you just have to add the myapp.service into the *.deb package with the proper path. Commented Jan 13, 2019 at 12:39
  • This is nice but it answers the question only partially. Where does this .service file go in the .deb file? How is the service activated by the .deb? Commented Mar 11, 2019 at 16:11

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.