How to run script at bootup in Debian

Hi all, I need to run a custom script at the later stage of bootup in Debian 9.5 (board is BeagleBone Black). I seem to remember "rc.local" long ago, but it's gone in the latest Ubuntu and Debian. Online search says (1) simply create "/etc/rc.local", and systemd will automatically pick it up. (2) use crontab, "@reboot ..." Which is "proper" way in Debian world?--William

On Tue, 22 Jan 2019 19:46:24 +0000 (UTC) William Park via talk <talk@gtalug.org> wrote:
Hi all, I need to run a custom script at the later stage of bootup in Debian 9.5 (board is BeagleBone Black). I seem to remember "rc.local" long ago, but it's gone in the latest Ubuntu and Debian. Online search says (1) simply create "/etc/rc.local", and systemd will automatically pick it up. (2) use crontab, "@reboot ..." Which is "proper" way in Debian world?--William
William, On my Fedora 27 laptop, placing rc.local into /etc/rc.d worked. /etc/rc.d/rc.local -- Howard Gibson hgibson@eol.ca jhowardgibson@gmail.com http://home.eol.ca/~hgibson

On Tue, Jan 22, 2019 at 03:09:59PM -0500, Howard Gibson wrote:
On Tue, 22 Jan 2019 19:46:24 +0000 (UTC) William Park via talk <talk@gtalug.org> wrote:
Hi all, I need to run a custom script at the later stage of bootup in Debian 9.5 (board is BeagleBone Black). I seem to remember "rc.local" long ago, but it's gone in the latest Ubuntu and Debian. Online search says (1) simply create "/etc/rc.local", and systemd will automatically pick it up. (2) use crontab, "@reboot ..." Which is "proper" way in Debian world? --William
William,
On my Fedora 27 laptop, placing rc.local into /etc/rc.d worked.
/etc/rc.d/rc.local
That's where it is on Slackware, too. But, I'm working with Debian 9.5 which comes with BeagleBone Black. I tried option (1), and it seems to work. -- William Park <opengeometry@yahoo.ca>

On Wed, Jan 23, 2019 at 12:24:53AM -0500, William Park via talk wrote:
On Tue, Jan 22, 2019 at 03:09:59PM -0500, Howard Gibson wrote:
On Tue, 22 Jan 2019 19:46:24 +0000 (UTC) William Park via talk <talk@gtalug.org> wrote:
Hi all, I need to run a custom script at the later stage of bootup in Debian 9.5 (board is BeagleBone Black). I seem to remember "rc.local" long ago, but it's gone in the latest Ubuntu and Debian. Online search says (1) simply create "/etc/rc.local", and systemd will automatically pick it up. (2) use crontab, "@reboot ..." Which is "proper" way in Debian world? --William
William,
On my Fedora 27 laptop, placing rc.local into /etc/rc.d worked.
/etc/rc.d/rc.local
That's where it is on Slackware, too. But, I'm working with Debian 9.5 which comes with BeagleBone Black. I tried option (1), and it seems to work.
Yes Debian does have a systemd service by default called rc.local.service which will execute /etc/rc.local if it exists and is executable of course. Certainly using a file in /etc/cron.d with an @reboot time would work well too. -- Len Sorensen

On 2019-01-23 9:43 a.m., Lennart Sorensen via talk wrote:
Certainly using a file in /etc/cron.d with an @reboot time would work well too.
Though cron doesn't guarantee that useful services will be up when @reboot is triggered. The hacky "it _almost always_ works" approach is to put a 'sleep' of appropriate length before your command. Writing a systemd service file isn't hard, though, and it allows fairly fine-grained control over when/how it runs: after network start, as a daemon or a one-shot, etc. I also like that you can run systemd services as a user. My better-than-nothing shutdown/reboot button for Raspberry Pi uses a very simple service to ensure it stays running: https://github.com/scruss/shutdown_button/blob/master/shutdown_button.servic... cheers, Stewart

On Wed, Jan 23, 2019 at 11:11:24AM -0500, Stewart C. Russell via talk wrote:
On 2019-01-23 9:43 a.m., Lennart Sorensen via talk wrote:
Certainly using a file in /etc/cron.d with an @reboot time would work well too.
Though cron doesn't guarantee that useful services will be up when @reboot is triggered. The hacky "it _almost always_ works" approach is to put a 'sleep' of appropriate length before your command.
Writing a systemd service file isn't hard, though, and it allows fairly fine-grained control over when/how it runs: after network start, as a daemon or a one-shot, etc. I also like that you can run systemd services as a user.
My better-than-nothing shutdown/reboot button for Raspberry Pi uses a very simple service to ensure it stays running: https://github.com/scruss/shutdown_button/blob/master/shutdown_button.servic...
Certainly. If your command relies on something specific, it would be best to make a proper startup handler for it. The rc.local.server runs after the network is up. That is all it promisses. As for cron, yeah timing of when that runs might not work for some things. -- Len Sorensen
participants (4)
-
Howard Gibson
-
lsorense@csclub.uwaterloo.ca
-
Stewart C. Russell
-
William Park