Having accepted that systemd is here, and accepting things have to be made to work with it, I decided to try and figure it out for myself.
I have got some way there which may help others trying to do the same, but I would appreciate some help and feedback from those more experienced with Linux and particularly with systemd experience.
This was the process I used. Files might not be in preferred places but it does at least work. I used upper-case just so things would stand out more amongst the systemd messages.
The first step was to get something to simply run under systemd which can be tweaked later to work as desired.
Create a shell script to run after boot-up. This will just output the date and time, put the same in a text file, and output a message to show that it is running ...
Code: Select all
sudo mkdir /etc/booted
sudo nano /etc/booted/booted.sh
#!/bin/sh -e
date > /booted.txt
date
echo "\n\nINSIDE BOOTED.SH\n\n"
exit 0
sudo chmod +x booted.sh
We also need to create a unit file so systemd can do its thing. We do not particularly care where in the process things are run, only that they are, so "After=syslog.target" and "WantedBy=multi-user.target" are just 'best guesses' for now ...
Code: Select all
sudo nano /etc/systemd/system/booted.service
[Unit]
Description=SCRIPT TO RUN AFTER BOOTING
After=syslog.target
[Service]
ExecStart=/etc/booted/booted.sh
Type=oneshot
[Install]
WantedBy=multi-user.target
Now we have to let systemd know about the added booted.service, and we need to enable that to be run when booted. And then we can reboot to see what happens. Note it's systemctl, C-T-L not systemctrl ...
Code: Select all
sudo systemctl daemon-reload
sudo systemctl enable booted.service
sudo reboot
And in the midst of all the boot-up messages we see "Starting SCRIPT TO RUN AFTER BOOTING..." and "[OK] Started SCRIPT TO RUN AFTER BOOTING",
but no date and no echoed "INSIDE BOOTED.SH" which should be shown when the booted.sh script runs.[SOLVED]
Logging in and /booted.txt has been created and is as expected which shows booted.sh did run, and "sudo systemctl -l booted.service" shows ...
Code: Select all
booted.service - SCRIPT TO RUN AFTER BOOTING
Loaded: loaded (/etc/systemd/system/booted.service; enabled)
Active: inactive (dead) since Sun 2015-10-04 18:32:37 BST; 6min ago
Process: 482 ExecStart=/etc/booted/booted.sh (code=exited, status=0/SUCCESS)
Main PID: 482 (code=exited, status=0/SUCCESS)
Oct 04 18:32:34 raspberrypi booted.sh[482]: Sun 4 Oct 18:32:34 BST 2015
Oct 04 18:32:34 raspberrypi booted.sh[482]: INSIDE BOOTED.SH
Oct 04 18:32:37 raspberrypi systemd[1]: Started SCRIPT TO RUN AFTER BOOTING.
So the date and echoed messages are shown by that but they never made it to the TV screen systemd listed messages.
Anyone know what I need to do to make that happen ?[SOLVED]
Also, if anyone knows what [Unit]Before=, [Unit]After= and [Install]WantedBy= settings should be to have something executing when systemd completes that would save me some researching and experimentation.