Easiest way to start a daemon - Pi Zero

Aug 11, 2023 Last reply: 2 years ago 9 Replies

Having finally fixed its bugs (don't ask) I have a perfect little daemon that pops itself in background and runs indefinitely, It isn't leaking memory and its not crashing and there is no reason it ever should, It accesses files but these will always be present and correct. It will never need to be killed or HUPed to relaod itself.



What is the absolute simplest way to autostart it. /etc/init.d and a script linked to etc/rc?.d? systemd?



Raspios is the Os.



...an @reboot line in crontab?

-- Take Back Control! -- Mesh The Planet! I do not play Nethack, I do play GNUS! o;-) Solid facts do not need 1001 pictures.

Yup, I guess that's another one! I'd forgotten that!

-- "Strange as it seems, no amount of learning can cure stupidity, and higher education positively fortifies it."

- Stephen Vizinczey

/etc/rc.local - if it still exists.

I've just installed pigpiod

/lib/systemd/system/pigpiod.service

[Unit] Description=Daemon required to control GPIO pins via pigpio [Service] ExecStart=/usr/bin/pigpiod -l ExecStop=/bin/systemctl kill pigpiod Type=forking [Install] WantedBy=multi-user.target

And then 'systemctl enable pigpiod.service' to put in a link in /etc/systemd/system/multi-user.target.wants

If you change the relevant lines, it should work.

Seems to. Whether it is as redundant as t*ts on a bull, is less obvious.

Ah, that looks neat. Is the "Type=forking" there to tell systemd not to expect it *not* to return?

Type=simple for a program that just goes off on its own.

As of some years ago it existed, but didn't do anything, in RPi OS. I found various guides online for enabling it with Systemd, none of which worked because Systemd obviously changes its workings every other week. I eventually wrote a script to perform all the ridiculously over-complicated and opaque configuration scripts to make it work on a fresh install. I posted that script once in this group. I won't bother digging it up again now because it seems extremely likely that by now Systemd will have changed again and it will be as broken in current RPi OS as the various outdated tutorials that I spent hours trying to follow originally.

The complication is wanting a process to run after everything else, not just after some specific things have been started. Systemd is designed to cater for the latter case, and if you're building the OS from the ground up that's probably fine, but making it so complicated to do the former is just unforgivable in my opinion.

I now consider RPi OS as just an example system from which to take inspiration for implementing software in a more sane, Systemd-free, environment.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required