You are not logged in.

#1 2013-08-10 14:19:58

jsham
Member
Registered: 2006-08-28
Posts: 4

systemd service delay

I'm trying have the following sequence occur on startup:

1) Load dvb_hdhomerun module
2) Wait for networking
3) Start userhdhomerun.service
4) Wait for userhdhomerun to find network devices
5) Start tvheadend.service

If I manually start the two services after reboot, everything works fine.

If I enable userhdhomerun.service, it has to restart itself several times before succeeding (I had to increase the RestartSec to 5):

Aug 10 09:41:15 xbmc systemd-modules-load[96]: Inserted module 'dvb_hdhomerun'
Aug 10 09:41:16 xbmc systemd[1]: userhdhomerun.service: main process exited, code=exited, status=255/n/a
Aug 10 09:41:16 xbmc systemd[1]: Unit userhdhomerun.service entered failed state.
Aug 10 09:41:21 xbmc systemd[1]: userhdhomerun.service holdoff time over, scheduling restart.
Aug 10 09:41:22 xbmc systemd[1]: userhdhomerun.service: main process exited, code=exited, status=255/n/a
Aug 10 09:41:22 xbmc systemd[1]: Unit userhdhomerun.service entered failed state.
Aug 10 09:41:27 xbmc systemd[1]: userhdhomerun.service holdoff time over, scheduling restart.
Aug 10 09:41:28 xbmc kernel: hdhomerun: userhdhomerun connected
Aug 10 09:41:28 xbmc kernel: hdhomerun: userhdhomerun connected

I think this is related to the network not being ready? userhdhomerun needs to find a device on the LAN to work correctly

Now if I also enable tvheadend, it restarts with userhdhomerun, but it finishes before userhdhomerun discovers the device on the LAN.

Relevant service files:

[Unit]
Description=Userspace daemon of the HDHomerun DVB driver
After=network.target

[Service]
ExecStart=/usr/bin/userhdhomerun -d
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target
[Unit]
Description=tvheadend
After=tmp.mount network.target userhdhomerun.service
Requires=userhdhomerun.service

[Service]
Type=forking
PIDFile=/run/tvheadend.pid
ExecStart=/usr/bin/tvheadend -f -p /run/tvheadend.pid -C -u hts -g video
ExecStop=/usr/bin/rm /run/tvheadend.pid
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

Is there a way to really delay the start of userhdhomerun.service until after the network is really operational?
Is there a way to delay the start of tvheadend.service until userhdhomerun has had a chance to discover devices on the netowork?

Offline

#2 2013-08-10 14:47:56

jsham
Member
Registered: 2006-08-28
Posts: 4

Re: systemd service delay

Here is a full dump of journalctl -b : http://pastebin.com/wxMAWk8v

and here is an annotated version:

Aug 10 09:41:15 #######booting
Aug 10 09:41:15 #######dvb_hdhomerun module added
Aug 10 09:41:15 xbmc kernel: HDHomeRun: Begin init, version 0.0.16
Aug 10 09:41:15 xbmc kernel: HDHomeRun: Waiting for userspace to connect
Aug 10 09:41:15 xbmc kernel: HDHomeRun: End init
Aug 10 09:41:15 xbmc systemd-modules-load[96]: Inserted module 'dvb_hdhomerun'
Aug 10 09:41:15 xbmc systemd[1]: Started dhcpcd on all interfaces.
Aug 10 09:41:15 xbmc systemd[1]: Starting Network.
Aug 10 09:41:15 xbmc systemd[1]: Reached target Network.
Aug 10 09:41:15 ########userhdhomerun starts immediately after dhcpcd service starts? this could be my problem
Aug 10 09:41:15 xbmc systemd[1]: Starting Userspace daemon of the HDHomerun DVB driver...
Aug 10 09:41:15 xbmc systemd[1]: Started Userspace daemon of the HDHomerun DVB driver.
Aug 10 09:41:15 ########tvheadend starts directly after userhdhomerun.service? this could be my problem
Aug 10 09:41:15 xbmc systemd[1]: Starting tvheadend...
Aug 10 09:41:15 xbmc systemd[1]: Started tvheadend.
Aug 10 09:41:15 ########userhdhomerun fails, maybe because i don't have an IP address yet
Aug 10 09:41:16 xbmc systemd[1]: userhdhomerun.service: main process exited, code=exited, status=255/n/a
Aug 10 09:41:16 xbmc systemd[1]: Unit userhdhomerun.service entered failed state.
Aug 10 09:41:15 ########userhdhomerun restarts, tvheadend restarts
Aug 10 09:41:21 xbmc systemd[1]: userhdhomerun.service holdoff time over, scheduling restart.
Aug 10 09:41:21 xbmc systemd[1]: Stopping tvheadend...
Aug 10 09:41:22 xbmc systemd[1]: Starting tvheadend...
Aug 10 09:41:22 xbmc systemd[1]: Started tvheadend.
Aug 10 09:41:22 ########userhdhomerun fails again
Aug 10 09:41:22 xbmc systemd[1]: userhdhomerun.service: main process exited, code=exited, status=255/n/a
Aug 10 09:41:22 xbmc systemd[1]: Unit userhdhomerun.service entered failed state.
Aug 10 09:41:26 ###finally got IP
Aug 10 09:41:26 xbmc dhcpcd[188]: enp2s0: leased 10.10.1.22 for 86400 seconds
Aug 10 09:41:26 xbmc dhcpcd[188]: enp2s0: adding host route to 10.10.1.22 via 127.0.0.1
Aug 10 09:41:26 xbmc dhcpcd[188]: enp2s0: adding route to 10.10.1.0/24
Aug 10 09:41:26 xbmc dhcpcd[188]: enp2s0: adding default route via 10.10.1.1
Aug 10 09:41:27 ########userhdhomerun restarts, tvheadend restarts
Aug 10 09:41:27 xbmc systemd[1]: userhdhomerun.service holdoff time over, scheduling restart.
Aug 10 09:41:27 xbmc systemd[1]: Stopping tvheadend...
Aug 10 09:41:28 xbmc systemd[1]: Starting tvheadend...
Aug 10 09:41:28 xbmc systemd[1]: Started tvheadend.
Aug 10 09:41:28 ########tvheadend completely executes, before DVB devices are created
Aug 10 09:41:28 ########hdhomerun finally finds the network device
Aug 10 09:41:28 xbmc kernel: hdhomerun: userhdhomerun connected
Aug 10 09:41:28 xbmc kernel: hdhomerun: userhdhomerun connected
Aug 10 09:41:28 xbmc kernel: hdhomerun: creating dvb device for 103BABA3-0
Aug 10 09:41:28 xbmc kernel: DVB: registering new adapter (HDHomeRun)
Aug 10 09:41:28 xbmc kernel: HDHomeRun HDHomeRun.0: DVB: registering adapter 0 frontend 0 (HDHomeRun ATSC)...
Aug 10 09:41:28 xbmc kernel: HDHomeRun0: DVB Frontend registered
Aug 10 09:41:28 xbmc kernel: HDHomeRun0: Registered DVB adapter0
Aug 10 09:41:28 xbmc kernel: hdhomerun: device /dev/hdhomerun_data0 created
Aug 10 09:41:28 xbmc kernel: hdhomerun: userhdhomerun connected

Offline

#3 2013-08-11 11:50:42

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 4,662

Re: systemd service delay

Afaik using After=network.target only ensures networking services are available, but doesn't make sure a specific network interface exists / is active when network.target is reached.

assuming userhdhomerun needs interface net0  , you might be able to use something like :

After=sys-subsystem-net-devices-net0.device

(taken from https://wiki.archlinux.org/index.php/Ne … ng_systemd )


Booting with apg Openrc, NOT systemd.
Automounting : not needed, i prefer pmount
Aur helpers : makepkg + my own local repo === rarely need them

Offline

#4 2014-08-25 18:25:56

surfhai
Member
Registered: 2010-06-26
Posts: 6

Re: systemd service delay

I've got a solution for my tvheadend setup. This one will wait for /dev/dvb/adapter0/dvr0 to be ready.

- add this line to /etc/udev/rules.d/99-dvb-card.rules
  http://www.mythtv.org/wiki/Systemd_myth … figuration

SUBSYSTEM=="dvb", TAG+="systemd"

- reboot or maybe the udevadm command suffices

# udevadm trigger

- now search for the needed device name with (search for "dvr0.device")
  http://www.mythtv.org/wiki/Device_Filen … uring_udev

# systemctl list-units

for me it is

sys-devices-pci0000:00-0000:00:1c.3-0000:04:00.0-dvb-dvb0.dvr0.device

- modify /usr/lib/systemd/system/tvheadend.service
add

Wants=sys-devices-pci0000:00-0000:00:1c.3-0000:04:00.0-dvb-dvb0.dvr0.device

change

After=tmp.mount network.target

to

After=tmp.mount network.target sys-devices-pci0000:00-0000:00:1c.3-0000:04:00.0-dvb-dvb0.dvr0.device

If you need a better name for the device, you'll find here something usefull to read
http://www.mythtv.org/wiki/Device_Filen … Rules_file

Last edited by surfhai (2014-08-25 18:32:12)

Offline

#5 2016-10-30 08:06:00

abc01234567890
Member
Registered: 2016-10-30
Posts: 1

Re: systemd service delay

Hi,

I have a service which needs to be started delayed, so I used service.timer:

# cat /etc/systemd/system/thinkfan.timer 
[Unit]
Description=simple and lightweight fan control program

[Timer]
OnStartupSec=60

[Install]                                                                                                                                                                        
WantedBy=multi-user.target         

 cat /etc/systemd/system/thinkfan.service 
[Unit]                                                                                                                                                                           
Description=simple and lightweight fan control program                                                                                                                           
After=syslog.target                                                                                                                                                              
Requires=systemd-modules-load.service                                                                                                                                            
                                                                                                                                                                                 
[Service]                                                                                                                                                                        
Type=forking                                                                                                                                                                     
ExecStart=/usr/sbin/thinkfan -D                                                                                                                                                  
PIDFile=/var/run/thinkfan.pid
ExecReload=/bin/kill -HUP $(</var/run/thinkfan.pid)

[Install]
WantedBy=multi-user.target

And seems it works.

Offline

#6 2016-10-31 11:43:14

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 5,903
Website

Re: systemd service delay

Great. Please don't necrobump though.

Closing.


Sakura:-
Mobo: ASUS P8Z77-V PRO // Processor: Intel Core i7-3770K 3.4GHz // GFX: nVidia GeForce GTX 970 Ti // RAM: 32GB (4x 8GB) Corsair DDR3 (@ 2133MHz) // Storage: 1x 3TB Seagate SATAII 5x 1TB Samsung SATAII, 2x 120GB Corsair SSD

Making lemonade from lemons since 2015.

Offline

Board footer

Powered by FluxBB