Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8918809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:50:36+00:00 2026-06-15T05:50:36+00:00

I’m using linux. I want a process (an irc bot) to run every time

  • 0

I’m using linux. I want a process (an irc bot) to run every time I start the computer. But I’ve got a problem: The network is bad and it disconnects often, so I need to manually restart the bot a few times a day. How do I automate that?

Additional information:
The bot creates a pid file, called bot.pid
The bot reconnects itself, but only a few times. The network is too bad, so the bot kills itself sometimes because it gets no response.

What I do currently (aka my approach 😉 )
I have a cron job executing startbot.rb every 5 minutes. (The script itself is in the same directory as the bot)

The script:

#!/usr/bin/ruby
require 'fileutils'

if File.exists?(File.expand_path('tmp/bot.pid'))
  @pid = File.read(File.expand_path('tmp/bot.pid')).chomp!.to_i
  begin
    raise "ouch" if Process.kill(0, @pid) != 1
  rescue
    puts "Removing abandoned pid file"
    FileUtils.rm(File.expand_path('tmp/bot.pid'))
    puts "Starting the bot!"
    Kernel.exec(File.expand_path('./bot.rb'))
  else
    puts "Bot up and running!"
  end
else
  puts "Starting the bot!"
  Kernel.exec(File.expand_path('./bot.rb'))
end

What this does:
It checks if the pid file exists, if that’s true it checks if kill -s 0 BOT_PID == 1 (if the bot’s running) and starts the bot if one of the two checks fail/are not true.

My approach seems to be quite dirty so how do I do it better?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:50:38+00:00Added an answer on June 15, 2026 at 5:50 am

    Restarting a application is a bad workaround, not a solution.

    i recommend to review the documentation of your bot, look for a option to configure after how many bad retries it exits or how to disable this functionality completely. if the bot is open source, you can also review its source code and modify the retry code. Try to find a clean solution.

    edit: nowadays, if your system is using systemd instead of init, create a service file /etc/systemd/system/bot.service for your bot like this:

    [Unit]
    Description=bot service
    After=network.target
    
    [Service]
    Type=simple
    Restart=always
    RestartSec=10
    ExecStart=/usr/bin/ruby /path/to/bot.rb
    
    [Install]
    WantedBy=multi-user.target
    

    This will restart the bot after 10 seconds. Also consider using the User= directive so it doesn’t run under root privileges, if not needed, or using the user instance of systemd. See the systemd documentation for more infos on the options. For the user systemd service see this question, the arch linux wiki and the official documentation.

    then start it with systemctl enable bot (starts the bot after reboot) and systemctl start bot

    alternatively, i would create a shellscript that runs the bot in a loop. make sure bot.rb does not fork into the background:

    #/bin/bash
    for (( ; ; ))
    do
         ./bot.rb
    done
    

    you can run that script with
    nohup ./startscript.sh &
    so it does not terminate if you close the console.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I have thousands of HTML files to process using Groovy/Java and I need to
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.