Write a script that runs a command for you
<p>So, here is my doubt:</p>

<p>I have some VPS with Ubuntu 15.04 headless that run a python script 24.7</p>

<p>I'd like to reboot the process every 8 hours without restarting the machine and giving it a 60 seconds delay between stop and start.</p>

<p>This may seem simple, but i'm struggling a bit on how to do this.</p>

<p>Thanks for your time.</p>

<p>I think it will be better (but not necessary) if you first daemonize your script so that it can be run as a service.</p>

<p><a href="http://stackoverflow.com/questions/1603109/how-to-make-a-python-script-run-like-a-service-or-daemon-in-linux">How to make a Python script run like a service or daemon in Linux</a></p>

<p>After that you should add two <a href="http://stackoverflow.com/questions/6423532/how-to-run-cron-job-every-2-hours">cron jobs</a>. Run your crontab editor</p>

<pre><code>crontab -e
</code></pre>

<p>Write this in the editor:</p>

<pre><code>0 */8 * * *  python /home/username/script.sh stop # stop every 8 hours
1 */8 * * *  python /home/username/script.sh start # start 1 minute after stopping
</code></pre>

<p>To make sure about the cron jobs timing check this <a href="http://crontab.guru" rel="nofollow">website</a>.</p>

python linux