54

I am using upstart for services on my servers. Writing a conf file and placing it in /etc/init is easy enough, but that doesn't seem to completely install. For one, the service --status-all doesn't list my new service. I checked and if I make a link in /etc/init.d to /lib/init/ubstart-job it'll show up in the status. But doing this manually makes me think I'm not doing it right, and there may well be other configuration steps which aren't being done.

What is the correct way to install an upstart service such that it is properly registered in all tools dealing with services?

2
  • 2
    This guy answered one of my questions using upstart service and gave a detailed explanation, it might point out a step that might have been missed askubuntu.com/a/278128/75967
    – Meer Borg
    Commented May 24, 2013 at 6:53
  • 1
    Did you mean /lib/init/upstart-job?
    – dalore
    Commented Jan 5, 2017 at 10:35

5 Answers 5

47

When you initially copy a new conf file into the /etc/init folder you need to call:

initctl reload-configuration

By this your upstart should be properly registered.

5
  • 8
    So this correctly sets up the job (ie, start and stop work) but it doesn't make the job show up in status all. I still had to manually add it to /etc/init.d/ for that to happen. Commented May 8, 2014 at 14:32
  • 1
    @JamesMcMahon You need to run initctl list command with sudo: sudo initctl list. That way you will see complete list of services.
    – Gelmir
    Commented Dec 19, 2014 at 14:39
  • Why the sudo, it doesn't appear to change the output of initctl list at all.
    – LovesTha
    Commented May 22, 2015 at 0:11
  • @JamesMcMahon, I still had to manually add it to /etc/init.d. You still had to add what? That means that, in addition to a X.conf file added to /etc/init, it's also necessary to add a file to /etc/init.d? Commented Jul 28, 2016 at 15:56
  • @KevinMeredith, Sorry I wasn't more detailed. It's been 2 years and I can't remember the specifics. If you look at into some init.d documentation it should hopefully be clear. Commented Jul 29, 2016 at 6:02
18

Checkout the service manual:

service --status-all runs all init scripts, in alphabetical order, with the status command. This option only calls status for sysvinit jobs, upstart jobs can be queried in a similar manner with initctl list.

(emphasis added)

That's why adding it to /etc/init.d (where the sysvinit jobs are located) made that work. So: try running initctl list instead :) .

2
  • 1
    That's why adding it Adding what? In addition to the my_service.conf file in /etc/init, it's also necessary to have an /etc/init.d file? Commented Jul 28, 2016 at 15:59
  • Not working with Ubuntu 16.04.4 LTS \\ $ initctl list initctl: Name "com.ubuntu.Upstart" does not exist $ sudo initctl list initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused
    – Andrew
    Commented Jul 6, 2018 at 18:29
15

For SysV Services

Make sure that you follow the following steps while adding/creating new service in Ubuntu.

  1. Create the service file in /etc/init.d/<service name>
  2. chmod 700 /etc/init.d/<service name>
  3. update-rc.d <service name> defaults
  4. update-rc.d <service name> enable

Now see you service in

service --status-all
3
  • 18
    your answer relates to sysv and not upstart. you may wish to delete it. Commented Mar 9, 2015 at 21:36
  • 4
    It's a usefull response indeed.
    – ATorras
    Commented Feb 28, 2016 at 18:30
  • altough it relates to another serivice, it is indeed usefull
    – wuppi
    Commented Jul 13, 2019 at 11:07
2

I've found that an error in the .conf file can make the job not recognizable to initctl. for example, having a setuid line in Upstart version 1.3 or earlier.

1
  • This. If there is an error it should show up in Upstart logs. Which could be any number of places depending on the version - for me on Ubuntu 10 (yes, really) they were in /var/log/syslog. Commented Apr 11, 2023 at 1:57
1

While the current chosen answer is correct for getting the new service added to upstart, it's not particularly helpful for finding out WHY a config in /etc/init/ is failing to load -- the missing piece is using init-checkconf first to make sure your config is valid, and then using reload-configuration:

####Test the new config - resolving any issues before continuing:
ERROR: File /etc/init/test.conf: syntax invalid:
test.conf:35: Unterminated quoted string

####then fix and recheck:
# init-checkconf /etc/init/test.conf
File /etc/init/test.conf: syntax ok

####then reload:
# initctl reload-configuration

#### and start:
# start test

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .