3

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)
s3lph
  • 14,314
  • 11
  • 59
  • 82
roady
  • 145
  • 2
  • 2
  • 7
  • Does the service start automatically? [edit] your post to add the output of systemctl status tvheadend. – muru Dec 20 '15 at 13:10
  • Could this be a simple case of relative pathnames? In particular, service is in /usr/sbin/ and start is in /sbin - which IIRC are not in cron's default path – steeldriver Dec 20 '15 at 14:00
  • Shouldn't you also be using systemctl start tvheadend? – s3lph Dec 20 '15 at 14:27
  • Yeay. the_Seppi, that did the trick! – roady Dec 20 '15 at 16:04
  • @the_Seppi you could post that as an answer. – muru Dec 20 '15 at 16:17
  • @steeldriver but cron will execute this script using bash, so bash's path will be used, which contains both /sbin/ and /usr/sbin by default. – s3lph Dec 20 '15 at 23:14
  • @steeldriver for some time now, cron reads /etc/environment, which has a default PATH defined including those directories. http://askubuntu.com/a/700126/158442 – muru Dec 20 '15 at 23:40

2 Answers2

3

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
gerardw
  • 449
3

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;
s3lph
  • 14,314
  • 11
  • 59
  • 82