You can analyze systemd boot sequence by following command. View the output file by using a SVG supporting web browser.
systemd-analyze plot > test.svg
That plotting will provide you last boot's timing statistics, which will provide you more clarified point of view to problem.
I solved my NFS mounting problem by adding mount
commands in to /etc/rc.local
. However I'm not sure, will it work with glusterd integration, worth a try for a quick fix. In order to make systemd run rc.local you should satisfy following condition:
# grep Condition /usr/lib/systemd/system/rc-local.service
ConditionFileIsExecutable=/etc/rc.d/rc.local
Well, assuming that the only thing changing per unit file is the remote.example.com
part, you can use an Instantiated Service.
From the systemd.unit
man page:
Optionally, units may be instantiated from a template file at runtime.
This allows creation of multiple units from a single configuration
file. If systemd looks for a unit configuration file, it will first
search for the literal unit name in the file system. If that yields no
success and the unit name contains an "@" character, systemd will look
for a unit template that shares the same name but with the instance
string (i.e. the part between the "@" character and the suffix)
removed. Example: if a service getty@tty3.service is requested and no
file by that name is found, systemd will look for getty@.service and
instantiate a service from that configuration file if it is found.
Basically, you create a single unit file, which contains a variable (usually %i
) where the differences occur and then they get linked when you "enable" that service.
For example, I have a unit file called /etc/systemd/system/autossh@.service
that looks like this:
[Unit]
Description=AutoSSH service for ServiceABC on %i
After=network.target
[Service]
Environment=AUTOSSH_GATETIME=30 AUTOSSH_LOGFILE=/var/log/autossh/%i.log AUTOSSH_PIDFILE=/var/run/autossh.%i.pid
PIDFile=/var/run/autossh.%i.pid
#Type=forking
ExecStart=/usr/bin/autossh -M 40000 -NR 5000:127.0.0.1:5000 -i /opt/ServiceABC/.ssh/id_rsa_ServiceABC -l ServiceABC %i
[Install]
WantedBy=multi-user.target
Which I've then enabled
[user@anotherhost ~]$ sudo systemctl enable autossh@somehost.example.com
ln -s '/etc/systemd/system/autossh@.service' '/etc/systemd/system/multi-user.target.wants/autossh@somehost.example.com.service'
And can intereact with
[user@anotherhost ~]$ sudo systemctl start autossh@somehost.example.com
[user@anotherhost ~]$ sudo systemctl status autossh@somehost.example.com
autossh@somehost.example.service - AutoSSH service for ServiceABC on somehost.example
Loaded: loaded (/etc/systemd/system/autossh@.service; enabled)
Active: active (running) since Tue 2015-10-20 13:19:01 EDT; 17s ago
Main PID: 32524 (autossh)
CGroup: /system.slice/system-autossh.slice/autossh@somehost.example.com.service
├─32524 /usr/bin/autossh -M 40000 -NR 5000:127.0.0.1:5000 -i /opt/ServiceABC/.ssh/id_rsa_ServiceABC -l ServiceABC somehost.example.com
└─32525 /usr/bin/ssh -L 40000:127.0.0.1:40000 -R 40000:127.0.0.1:40001 -NR 5000:127.0.0.1:5000 -i /opt/ServiceABC/.ssh/id_rsa_ServiceABC -l ServiceABC somehost.example.com
Oct 20 13:19:01 anotherhost.example.com systemd[1]: Started AutoSSH service for ServiceABC on somehost.example.com.
[user@anotherhost ~]$ sudo systemctl status autossh@somehost.example.com
[user@anotherhost ~]$ sudo systemctl status autossh@somehost.example.com
autossh@somehost.example.com.service - AutoSSH service for ServiceABC on somehost.example.com
Loaded: loaded (/etc/systemd/system/autossh@.service; enabled)
Active: inactive (dead) since Tue 2015-10-20 13:24:10 EDT; 2s ago
Process: 32524 ExecStart=/usr/bin/autossh -M 40000 -NR 5000:127.0.0.1:5000 -i /opt/ServiceABC/.ssh/id_rsa_ServiceABC -l ServiceABC %i (code=exited, status=0/SUCCESS)
Main PID: 32524 (code=exited, status=0/SUCCESS)
Oct 20 13:19:01 anotherhost.example.com systemd[1]: Started AutoSSH service for ServiceABC on somehost.example.com.
Oct 20 13:24:10 anotherhost.example.com systemd[1]: Stopping AutoSSH service for ServiceABC on somehost.example.com...
Oct 20 13:24:10 anotherhost.example.com systemd[1]: Stopped AutoSSH service for ServiceABC on somehost.example.com.
As you can see, all instances of %i
in the unit file get replaced with somehost.example.com
.
There's a bunch more specifiers that you can use in a unit file though, but I find %i
to work best in cases like this.
Best Answer
Try
PartOf=
From https://www.freedesktop.org/software/systemd/man/systemd.unit.html: Configures dependencies similar to Requires=, but limited to stopping and restarting of units. When systemd stops or restarts the units listed here, the action is propagated to this unit. Note that this is a one-way dependency — changes to this unit do not affect the listed units.