0

I'm a bit newbie in the raspberry world, and Linux commands, etc..

I installed a hangoutbots in Raspberry and I launch it in terminal as tutorial said.

But my problem is that I need it to have "24/7", so I need to launch terminal and start automatically if raspberry goes down for some reason.

What I have to do in a terminal to launch the bot, is:

>cd DEsktop/BotHangout/hangoutsbot

>python3 hangoutsbot/hangupsbot.py 

So after all this explanation, my question is:

Is there anyway to launch automatically on raspberry start? (Some type os script, or make "launcher"...)

Kolban
  • 1,784
  • 2
  • 16
  • 28
Shudy
  • 103
  • 3
  • hangoutbots project provides a systemd .service file as an example https://github.com/hangoutsbot/hangoutsbot/blob/master/examples/hangupsbot.service – superbob Nov 23 '16 at 07:16

2 Answers2

1

You can make a cronjob by editing your crontab file. Here is what you will want to do:

Install screen, that way you can resume it in your terminal when you want to. You can install screen by entering:

sudo apt-get install screen

Then, you will need to enter the command:

crontab -e

This will open up your crontab file, where you will be able to set your startup commands.

At the bottom of the file, add this:

@reboot screen -d -m -S Hangoutbot python3 /home/pi/Desktop/BotHangout/hangoutsbot/hangupsbot.py

Then save the file with command x and then y and then enter.


Command Breakdown:

@reboot says to run the following command on startup.

screen -d -m -S Hangoutbot says to run the following command in the background and name the screen Hangoutbot.

The rest of the command is the python command that will run your python code.


Once booted, the command will be running in the background, if you want to attach it and watch/interact with it, you will need to enter the command:

screen -r Hangoutbot
Patrick Cook
  • 6,365
  • 7
  • 37
  • 63
  • I tried it. I have done all the steps, but when I reboot RPi, it doens't work.(trying to see it with screen -r Hangoutbot, bu if I opened a terminal ,and tested just the command screen -d -m -S ...... this worked. – Shudy Feb 16 '16 at 11:07
  • May be is possible it don't work correctly, because I'am accesing to RPi via Tightvnserver ? – Shudy Feb 16 '16 at 11:28
  • @Shudy it shouldn't matter how you're connected to your Pi. Try crontab -e again and make sure that the crontab saved. – Patrick Cook Feb 16 '16 at 21:48
  • sorry to not answer before, I was a bit bussy. Finally I checked the crontab as you said, and It was my Fault. The rute to the *.py file was with a typo. Now it works PERFECT.

    Thanks a lot

    – Shudy Feb 18 '16 at 10:59
0

It may be that your question is an example of "How do I start a program when the Pi boots?" which I believe has been asked and answered a couple of times. My personal preference for solving this problem is to used systemd. I'd suggest googling around on systemd. There is also a tutorial video on setting up systemd to run an arbitrary command ... see:

https://www.youtube.com/watch?v=eEuViHanjKI

Kolban
  • 1,784
  • 2
  • 16
  • 28