Make bot restart automatically every night


Bot version:
OS: Linux/Ubuntu (Raspberry Pi 3)

I’m not very handy with Ubuntu because I’ve only started playing with it when I got my Pi. I notice every now and then that my bot shuts down every now and again (Not sure why). I always presume it’s because it’s been running for too long, and ran out of memory or something. Typically I just unplug the pi and plug it back in, and this does the trick.

I was wondering if there was a command I could use or something I could add in a system file to make the bot restart itself, every night, at 2am (during off-hours) for example. That way, I could avoid any potential errors when I need my bot.


Did you setup the bot as a service or are you running it in the foreground? This will determine the options.


I think it is setup as a service? I used the guide here to help me set it up initially. And I followed it to the letter:Ubuntu 16.04 LTS Setup Guide


If you start your bot up via systemctl (like mentioned in that article) simply add a cronjob as root once a day:

# Restart PhantomBot at 02:00am
00 02 * * * /bin/systemctl restart phantombot

For more information on cron, please read:



Ok but I have to do this once a day? I can’t add something to a file that will do it automatically for me without requiring me to input something every day, so I don’t have to worry about it?


No, read the page I linked. Cron will run things at certain times so you don’t have to worry about it.

Cron is a system daemon used to execute desired tasks (in the background) at designated times.



That’ll teach me to pay attention to what someone writes in their response.

Much obliged Illusionary! Thank you for the quick response.


No problem! I figure that page can explain cron better than I could, or I would have probably just cut/pasted most of the article here :slight_smile:

Basically, you will use crontab -e as root to insert the line I showed you, I just figured reading up on what cron is and how to edit the files and list the files and so on is good if you are new to Ubuntu as well.

If you need anything else, let us know!


closed #9

This topic was automatically closed after 30 days. New replies are no longer allowed.