Hi, Is it possible to have my droplet/server restart daily at a certain time? Then once restarted, either have it login automatically or run a command to run an application automatically? The reason why I need to do this is because I have an application running and after some time it starts to lag, and until I restart the droplet, it will lag and lag.
The command I need my droplet to run after restarting is something like : sudo screen ./TS3MusicBot_runscript.sh -parameters -parameters -parameters
I’m not sure if I could run that command without having to SSH into my droplet.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
You can use crontab for that. Log in as root and run crontab -e. Once inside the editor, add the following line:
0 0 * * * reboot
This will reboot the server every day at midnight.
In order to then run a command after reboot, you can add another line to crontab like this:
@reboot screen ./TS3MusicBot_runscript.sh -parameters -parameters -parameters
In order for this to work under Debian/Ubuntu, you may have to run this command as root:
update-rc.d cron defaults
Another approach is to create a startup script in /etc/init.d (Debian/Ubuntu) with the following content:
#!/bin/sh
case "$1" in
start)
screen ./TS3MusicBot_runscript.sh -parameters -parameters -parameters
exit 0
;;
stop)
exit 0
;;
reload|restart|force-reload)
exit 0
;;
**)
echo "Usage: $0 {start|stop|reload}" 1>&2
exit 1
;;
esac
In case you choose this approach, then remember to do the following:
chmod +x /etc/init.d/musicbot
update-rc.d musicbot defaults
Hi,
thank you for that post, I tried the first method, which is :
crontab -e
Then put0 0 * * * rebootat the end
and then
@reboot screen ./TS3MusicBot_runscript.sh -parameters -parameters -parameters
And lastly
update-rc.d cron defaults
For some reason my system does not reboot at midnight. It also doesn’t runt he command when I reboot it myself.
I use the command sudo reboot now but my system doesn’t actually turn off.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.