Start screens automatically after rebooting the server

February 24, 2016 3k views
Ubuntu DigitalOcean Linux Commands


I was wondering how I can have some bots start automatically after boot. I have a music bot on a vps for a discord server and I was wondering how to have it start backup automatically from its directory.

I am running it in Ubuntu Ver 14


1 Answer

What’s the command you type at the console, and where is the executable located? Once you have this info, all you usually need to do is edit the file /etc/rc.localand place it before the exit command. Make sure you end the command you add with an ampersand(&) to make sure that it runs in the background.
For example, if you’re command is “discord somearghere” and your executable is located in /opt/discord/bin/discord, insert the following in /etc/rc.local

    /opt/discord/bin/discord somearghere &
  • I go into the directory discord

    Then screen -S bot and then python3.5

    • @CrypticCube - after you start it, do you still need the terminal for entering data, or do you just let it run indefinitely and switch to another screen? Also, when you say “I go into the directory discord” is that starting from your home directory?

      • No. All I need for is to do it go into the directory /root/discord then start the screen.

        • Try inserting this line in /etc/rc.local before the “exit 0” line:

          /usr/bin/screen -S bot -d -m /usr/bin/python3.5 /root/discord/

          I don’t believe ampersand is needed since it should start it detached. After bootup, when you log back in you should see it in your screen list.

Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!