brent timothy saner on 8 May 2017 05:55:00 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Systemd Startup Sequence Question


On 05/08/2017 08:32 AM, Casey Bralla wrote:
> I've decided I am not a fan of systemd.   I was very familiar with Debian's 
> sysvinit and Gentoo's OpenRC systems, and could easily add/delete services 
> with high reliability.   One thing I loved in both systems was the easy way of 
> adding misc programs to be run at the end of the boot sequence (/etc/rc.local 
> for Debian and /etc/local.d in Gentoo).
> 
> I have always used these to mount my NFS share drives at the end of boot-up.
> 
> Now that I'm running Arch with systemd, things are not so simple.   AFAIK, 
> Arch has no simple built-in system to run a misc program at boot time.  
> However, I loaded an rc.local program from the Arch User Repository (AUR), 
> which is supposed to be functionally equivalent to the Debian system I'm 
> familar with.
> 
> Except, mounting NFS shares does not work.  I get a "network name not 
> recognized" error at start-up.   Once I log in, however, I can manually run 
> the rc.local batch file and the shares mount without any trouble.
> 
> 
> I presume rc-local is running before the entire entworking system is 
> operational.   Is there a way I can delay the rc.local batch file until truly 
> all other systemd processes have started?
> 
> 
> Anybody got any ideas?
> 
> TIA!
> 

first step, stop and learn[0] to create[1] unit[2] files[3]. trust me.
you'll thank me in about two weeks. they're easy to learn and simple INI
structured. speaking as someone who's written RC/sysVinit scripts and
systemd unit files, i vastly prefer the latter.

secondly, systemd uses a parallel and dependency-based init system, NOT
a sequential system. forget rc.local or any tool trying to retrogradedly
slap in functionality of it. it's holding you back.

to implement your own startup process, create a unit file. if you have a
script you're trying to run that you wrote yourself, you'll probably
want something like this:

#############
[Unit]
Description=Some Custom Jobby Doodad
# Based on your email, you probably want network.target as a dependency.
# You can specify multiply dependencies, though.
After=network.target

[Service]
# "oneshot" is a blocking operation, but you get state status.
#Type=oneshot
# "simple" is non-blocking but you don't get reliable reporting on
#   the process' exit code.
Type=simple
# If User and Group aren't specified, defaults to root.
User=someuser
Group=somegroup
ExecStart=/absolute/path/to/script

[Install]
WantedBy=multi-user.target
#############

write it as /etc/systemd/system/foobar.service (obviously replacing
foobar with something more descriptive). note that this is a terribly
barebones unit file. refer to the links i give at the footnote for info
on creating more complex units; it's immensely powerful.

then:

systemctl daemon-reload
systemctl enable foobar.service  # or whatever you named it
# and optionally, start it immediately if you need it now
systemctl start foobar.service

done. that's it. that's literally it. i'd encourage you to look at the
other system/package-provided unit files in /usr/lib/systemd/system/ for
other examples.

[0] https://www.freedesktop.org/software/systemd/man/systemd.unit.html
[1]
https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files
[2]
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sect-Managing_Services_with_systemd-Unit_Files.html
[3] https://wiki.archlinux.org/index.php/systemd#Writing_unit_files

Attachment: signature.asc
Description: OpenPGP digital signature

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug