0

I have created my own upstart script in /etc/init, which I can start and stop.

Now I want that service to be restarted when a file (/etc/my-app/restart-requested.txt) exists (or better is touched).

My solution with previous /etc/init.d/ service was a cron-job which regularily checked for the restart-file and called restart when the file existed.

Is there a better solution with upstart?

Witek
  • 1,433
  • 3
  • 14
  • 16
  • 1
    Use inotify - http://www.cyberciti.biz/faq/linux-inotify-examples-to-replicate-directories/ – Panther Jun 12 '14 at 19:22
  • http://linux.die.net/man/1/inotifywait , wait for a file and do your action. http://unix.stackexchange.com/a/24955/29187 – ADM Jun 12 '14 at 21:17

2 Answers2

1

6 years later I've found out that upstarts guarantees that it first processes stop on and then start on:

http://upstart.ubuntu.com/cookbook/#ordering-of-stop-start-operations

This means that you can use

start on file FILE=/etc/my-app/restart-requested.txt EVENT=modify
stop on file FILE=/etc/my-app/restart-requested.txt EVENT=modify

Probably you don't need it anymore but I've faced same issue and found your question so maybe someone can use this solution in the future as well.

synek317
  • 111
  • 1
0
  1. Install incron
  2. Put /etc/my-app/restart-requested.txt IN_CLOSE_WRITE restart myservice into /etc/incron.d/myservice
Witek
  • 1,433
  • 3
  • 14
  • 16