[systemd-devel] Auto-start of a Service in systemd
hurikhan77 at gmail.com
Thu Oct 6 17:22:06 UTC 2016
Am Wed, 5 Oct 2016 18:00:41 +0530
schrieb "Raghavendra. H. R" <raghuhr84 at gmail.com>:
> Your doubt is absolutely correct. Default target of the system as
> nothing to do with auto start of services.
> I checked both graphical.target & multi-user.target, surprisingly I
> don't see any big difference in these. Both of the files are almost
> same except multi-user.target have dependency *After=* with
> *rescue.service & rescue.target* which is restricting
> multi-user.target from starting.
> However graphical.target don't depend on rescue services, so it is
> active & started. And by making graphical.target as dependency in my
> unit file solved my problem.
> Hopefully if I remove the rescue services dependency from
> multi-user.target and add it as dependency then my service should
> come up without failures.
"After=" does not have such an impact. It won't block a service from
starting if the services in "After=" aren't started. It's just an
ordering dependency. If the dependents aren't enabled they are just
ignored. Instead, "Requires=" and "Wants=" give stronger dependencies.
You can check the status of multi-user.target:
$ systemctl status multi-user.target
● multi-user.target - Multi-User System
Loaded: loaded (/usr/lib/systemd/system/multi-user.target; static; vendor preset: disabled)
Active: active since Mo 2016-10-03 16:44:14 CEST; 3 days ago
Okt 03 16:44:14 jupiter.sol.local systemd: Reached target Multi-User System.
$ systemctl get-default
As you see, multi-user.target has been pulled in for me. You can check
the order of targets started with:
$ systemd-analyze critical-chain
The time after the unit is active or started is printed after the "@" character.
The time the unit takes to start is printed after the "+" character.
└─systemd-nspawn at gentoo\x2delasticsearch\x2dbase.service @2.219s +3.164s
└─systemd-networkd.service @2.031s +172ms
└─docker.socket @1.896s +24ms
└─systemd-timesyncd.service @1.649s +239ms
└─systemd-tmpfiles-setup.service @1.576s +66ms
└─systemd-tmpfiles-setup-dev.service @383ms +179ms
└─kmod-static-nodes.service @148ms +42ms
Also, take note that "After=" doesn't wait for a service to finish
its startup. Maybe, your service is just triggered way to early? You
may want to add "After=network.target" or similar synchronization
points of the graph above.
Make sure that after editing "WantedBy=" you may need to "systemctl
reenable" your service. If you didn't use "systemctl edit --full" you
may also need to use "systemctl daemon-reload" before re-enabling the
service. Otherwise you may see strange effects similar to what you
> Thanks for your valuable feedback.
> Raghavendra H R
> Raghavendra. H. R
> On Wed, Oct 5, 2016 at 4:55 PM, Andrei Borzenkov <arvidjaar at gmail.com>
> > On Wed, Oct 5, 2016 at 1:19 PM, Raghavendra. H. R
> > <raghuhr84 at gmail.com> wrote:
> > > It's working fine now. We should give the default target of the
> > > system
> > for
> > > WantedBy= of the Install section.
> > > So I used graphical.target in the Install section and it fixed my
> > > issue.
> > I doubt it was the reason. grpahical.target pulls in
> > multi-user.target unless you have very customized unit definitions.
Replies to list-only preferred.
More information about the systemd-devel