Ubuntu – From init.d to upstart, is there a bridge


I've got a perfectly good script for use in /etc/init.d. In fact, I have a lot of them, all created with the Tanuki Java Service Wrapper.

It would seem to me that there could be a simple template for wrapping such a shell script up as an upstart script, but a bit of googling is not revealing one.

Am I missing something?

Best Answer

  • I don't recall seeing a template for this. Its a bit ironic, however, that technically, its upstart that is starting your init.d script in the first place thanks to the backward compatibility job rc and rcS.

    I would consider rewriting whatever you have as an upstart job, however, I know that some scripts are difficult to convert, so here's what I did for a while on some of my scripts:

    description "xyz"
    author "xyz"
    start on runlevel 5
    stop on runlevel [!5]
    pre-start script
        # do my work here to start the service
    end script
    post-stop script
        # do work here to stop the service
    end script

    Now depending on the nature of the service, whether it persists or forks itself, you may need to add expect fork or task to the job file.

    Just to complete the thought, usually, this is all there is to a full upstart job file anyway. All of the pre start work is done, all of the cleanup is done, the only thing remaining is the service itself which is usually added with:

    exec service_cmd
  • Related Question