How to run python program automatically without ssh into server

This guide will help you if you want run python program automatically without ssh every time into server.

Supervisor ----

Supervisor: A Process Control System
Supervisor is a client/server system that allows its users to monitor and control a number of processes on UNIX-like operating systems.

Let’s Create supervisor program to ensure any command runs in the background and restarts if the server is restarted.

Step 1. Installing Supervisor

sudo apt-get install supervisor -y 

Step 2. Starting Supervisor service

sudo service supervisor start

Step 3. Creating a conf file

sudo nano /etc/supervisor/conf.d/autostart.conf

Step 4. Setup configuration

[program:autostart]
user=ubuntu
directory=/home/ubuntu/iot_project
command=python3 demo.py
autostart=true
autorestart=true

Note : Change the following according to your need in conf file

  • user= set server user
  • directory= path of directory where your python files are located
  • command= python3 your_python_file_name.py

Step 5. Reread supervisor conf

sudo supervisorctl reread

Step 6. Update supervisor

sudo supervisorctl update

Setp 7. Restart supervisor

sudo supervisorctl restart all

To Stop supervisor

sudo supervisorctl stop all

Note : Remember Bolt Cloud has API hit rate limit

Below are the number of API calls which you are allowed to do in the specific time duration.
Your API access will be temporarily blocked if the number of hits crosses mentioned thresholds

Time duration | Allowed API hits [Free Plan] | Allowed API hits [Pro Plan]
----------------------------------------------------------------------------
  1 min       |            20                |         240
  6 mins      |            72                |         1,400
  30 mins     |            360               |         6,600
  60 mins     |            720               |         1,32,000
1 Like