I'm working on a slackbot and I have to stop it and start it every time I make a change. I've worked in environments where simply saving a file caused the process to restart. It would also be cool if it restarted a few times if it just died.

I know I've used tools like this in the past, but I can't remember what they were called, and my web searches are turning up nothing.

I'm working in linux.

Thank you!

P.S. what tag would you use for tools to make coding easier? I didn't find one that made sense.

3 Replies 3

The base functionality you're looking for is Linux's inotify, available in Python through the inotify module. inotify can monitor a file or directory and report when it changes.

For restarting when the process dies, you either need to code a monitor process into your python script, or use an external monitor process (such as the system startd or a user-level similar process).

For file/dir monitoring use the inotifywait in a shell script. E.g. inotifywait -q -e modify "$scriptname" && restart_commnad_here in a loop. The standard program for starting/stopping/restarting (and much more) is called systemd, in this case a systemd --user instance. If you are not familiar with systemd, you'll need a lot of learning time.

Thanks guys! I settled on a script using inotifywait. I was hoping for something more complete than a command for a script I'd write and less comprehensive than systemd.

Your Reply

By clicking “Post Your Reply”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.