Rich Freeman on 8 May 2017 06:35:43 -0700


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

Re: [PLUG] Systemd Startup Sequence Question


On Mon, May 8, 2017 at 8:54 AM, brent timothy saner
<brent.saner@gmail.com> wrote:
>>
>> 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?
>>

It sounds like you don't need EVERYTHING running - just NFS.

So, you want an After=remote-fs.target dependency I believe.

If it needs just the network and not NFS in particular you can use
network.target.

The gentoo implementation of this sets After=multi-user.target
graphical.target which does run it after just about everything else.

>
> 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.

++

While a little script in local.d can work, you lose a lot of the
granularity of an actual unit, and a unit is pretty trivial to write.

The biggest issue a lot of people seem to have with units is
understanding how to use targets.  man systemd.special will give you a
list of them.  Ideally you should pick the most specific target you
need, such as network, or local-fs, or remote-fs.  You can also depend
on a specific service if needed, such as if apache should load after
mariadb.

If you have an existing service and want to add a dependency to it you
should use a drop in, for example:
cat /etc/systemd/system/mythbackend.service.d/00rich.conf
[Unit]
After=mariadb-contain.service mariadb-wait-online@mariadb.service
nss-lookup.target
Wants=mariadb-wait-online@mariadb.service

[Service]
Nice=-5
IOSchedulingClass=1
Restart=always

This uses the distro-supplied unit, but adds some dependencies so that
it runs after my mariadb container is running, and DNS is working
(since was on the same host and thus doesn't exist the moment the
network is up).  It also sets some nice-to-have settings for
scheduling and tells it to auto-restart.  The mariadb-wait-online
instanced service basically pings a mariadb server on the named host
until it is alive, which is needed since mariadb was running in a
separate container and thus simply launching the container did not
guarantee it is running yet.  I think I stole it from somebody.

I think this also shows some of the benefits of units.  Doing all of
the above under openrc would have been a bit of a pain and less
modular.

-- 
Rich
___________________________________________________________________________
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