Quantcast
Channel: openSUSE Forums
Viewing all articles
Browse latest Browse all 40713

systemd - run a script during boot with network connection and before login screen appears

$
0
0
I want to have a script run during boot. The script needs a working network connection and the login screen must not display until this script is finished. The script could start the network itself if necessary and determine when it is up. The network is controlled by 'traditional with ifup'. This was easy to do with sysv init but is starting to seem impossible with systemd. Getting a script to run during boot is easy but getting it to do what I want is another matter entirely. The closest I've got so far is this for my service file /etc/systemd/system/mine.service
Code:

[Unit]
Description=mine
DefaultDependencies=no
After=sysinit.target local-fs.target
Before=basic.target

[Service]
Type=oneshot
ExecStart=/opt/mine/blahblahblah

[Install]
WantedBy=basic.target

I got this from http://lists.freedesktop.org/archive...er/000225.html

/opt/mine/blahblahblah looks like
Code:

#!/bin/bash
out="/dev/shm/$(basename $0)_out";
> "${out}";
date >> "${out}";
#systemctl start network
for i in {1..30};do
sleep 1;
ifconfig -a >> "${out}";
done
date >> "${out}";

This works in as much that the script runs during boot and holds up the boot process for 30 seconds whilst it runs. But I can't get the network up. Nothing I add to the Unit section results in the network coming up. You can see in the script I've commented out a line 'systemctl start network'. If that's uncommented the boot process never finishes, it gets stuck trying to run my script seemingly for ever. The system is unusable until I boot from alternative media, mount the relevant partition and edit the script.

I also want to have a script run during shutdown with a working network connection, but I figure if I can get the boot script working as desired getting the shutdown script working should be easy enough to figure out.

For a while I've had in my mind that if I found I was unable to make systemd do what I want my fall back option was to use /etc/init.d/boot.local, but as someone has recently pointed out in another thread, systemd makes a lie of the comments in /etc/init.d/boot.local. boot.local gets called by /usr/lib/systemd/system/rc-local.service and that contains
Code:

After=network.target
And that it seems could mean pretty much anything and also you're wrong if you want to do things after you know the network is up:
http://www.freedesktop.org/wiki/Soft...NetworkTarget/

Viewing all articles
Browse latest Browse all 40713

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>