Run application on Linux server boot

I run two twitter bots:

  1. The Constitution Bot (@SamvidhanBot) / X
  2. Vivekam (@voiceofvivekam) / X

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.



Varun Kalyan

Data scientist | Product & Strategy ??? | Writer | Toastmaster

3 个月

Cron jobs are another good way to implement this. Following your twitter threads now!

要查看或添加评论,请登录

Sai Krishna Dammalapati的更多文章

社区洞察

其他会员也浏览了