My job is dependent on MySQL. So I want my job could startup after MySQL.

I read the upstart cookbook and I find start on can auto start a job.

start on started mysql

And it works. But I don't want mysql will affect my job after boot. When I stop my job, it will be restarted by restarting mysql. How to avoid this?


Create a lock file in /tmp/ folder to track that your job already run. Here an example:

  1. Create these two upstart jobs configuration files:


    # job A
    start on local-filesystems
    stop on runlevel[016]
      /bin/echo job-A started >> /tmp/myjobs.log
      exec sleep 5
    end script


    # job B triggered after A
    start on started joba
      /bin/echo job-B started >> /tmp/myjobs.log
      if ! [ -f /tmp/jobb.lock ]
        /bin/echo " do job-B tasks" >> /tmp/myjobs.log
        /bin/touch /tmp/jobb.lock
        /bin/echo " bypass job-B tasks"  >> /tmp/myjobs.log
      exec sleep 5
    end script
  2. Reboot

  3. Check cat /tmp/myjobs.log or open sudo tail -f /tmp/myjobs.log in another window.
  4. Try run job-A again sudo start joba
  5. Check /tmp/myjobs.log, see bypass note:

    job-A started
    job-B started
     do job-B tasks
    job-B started
     bypass job-B tasks
    job-A started
    job-B started
    job-A started
     bypass job-B tasks

Note: For each run, we have 3 lines. It does not matter lines sorting here. stdout buffering issue, it is not related to upstart. The jobs are run in the correct sequence.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.