Delay startup service

I want to delay start an service on boot. Ubuntu Server 15.10

I’ve created the file /startup-tvheadend.sh (chmod +x)

#!/bin/bash 
sleep 20 && service tvheadend start;

Then in crontab -e

@reboot /startup-tvheadend.sh

Running the script as sudo works but not when I reboot the computer.
I’ve disabled the default auto start after installation.

kidkic@TvHeadEnd:~$ systemctl status tvheadend
‚óŹ tvheadend.service - (null)
   Loaded: loaded (/etc/init.d/tvheadend)
   Active: inactive (dead)
     Docs: man:systemd-sysv-generator(8)
Asked By: roady

||

As you are using systemctl status tvheadend, I guess you should also use systemd’s systemctl instead of upstart’s service command to start this service:

#!/bin/bash 
sleep 20 && systemctl start tvheadend;
Answered By: s3lph

It’s simpler to add a sleep to the systemd configuration file. For example, to delay the bind9 start, we can edit (On Ubuntu 16.04) /lib/systemd/system/bind9.service and add a ExecStartPre command. (See https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files )

[Service]
ExecStartPre=-/bin/sleep 5
EnvironmentFile=/etc/default/bind9
Answered By: gerardw
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.