Run application on Linux server boot
I run two twitter bots:
Both post a tweet every hour from a database of constitutional insights and Swami Vivekananda’s wisdom. I hosted them on my Raspberry Pi. You can find the codes here: SamvidhanBot | VivekamBot
However, there was one challenge. Whenever there was a power cut, I had to manually run the application when the power comes back. This led to inactivity of my bots.
Then I figured out a small way to run applications whenever the linux server boots.
First open the rc.local file in an editor. rc.local is useful to run commands at system startup. It is executed as the last part of the system boot process, after all other system services have been started.
sudo nano /etc/rc.local
Add the following code at the end of the rc.local file.
sleep 60
/bin/bash /home/chaoticneuron/SamvidhanBot/run_bot.sh
/bin/bash /home/chaoticneuron/Vivekam/run_bot.sh
exit 0
After booting, the script pauses for 60 seconds and then proceeds to execute two bot scripts. Unless the machine is not connected to the internet, the applications will start working.
Data scientist | Product & Strategy ??? | Writer | Toastmaster
2 个月Cron jobs are another good way to implement this. Following your twitter threads now!