Skip to content

Latest commit

 

History

History
177 lines (118 loc) · 3.52 KB

setup.md

File metadata and controls

177 lines (118 loc) · 3.52 KB

Here's a guide to setup this userbot on a server

In no means is this guide optimized or the only way for setup, I just run it this way

Update packages and install needed ones

sudo apt update && sudo apt upgrade && sudo apt -y install gnupg2 wget vim git gcc python3-dev build-essential python3-venv libpq-dev psycopg2-binary
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt update && sudo apt upgrade && sudo apt -y install npm nodejs

Install pm2 to manage the app and to run in background

npm install pm2@latest -g
If the above command gives an error
sudo mkdir /usr/local/lib/node_modules
sudo chown -R $USER /usr/local/lib/node_modules

Setup pm2 to run at startup

pm2 startup

then run the line that it says to run

Setup Postgresql 14

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt -y update
sudo apt -y install postgresql-14

Setup postgres user, replace $PGUSER with a username u want for postgres

sudo su - postgres

createuser -P -s -e $PGUSER

Then enter a pass when prompted and remeber it


If it shows that the pass starts with SCRAM then do the following

Edit the postgresql.conf and switch to md5 password_encryption

Look for Authentication section then password_encryption and set it to md5 (it was scram-sha-256) and uncomment the line if commented

sudo vim /etc/postgresql/14/master/postgresql.conf

Edit the pg_hba.conf and switch the authentication to md5

Look for the scram and replace them by md5

sudo vim /etc/postgresql/13/master/pg_hba.conf

Then change the user password

psql
ALTER USER $PGUSER WITH PASSWORD 'NEW_PASSWORD_HERE';
ctrl + d

Create a database for the userbot

createdb -O $PGUSER fizi

database url will be postgresql://$PGUSER:$PASS@localhost:5432/fizi

replace $PASS and $PGUSER with the ones you chose

If you want to migrate a remote database to the local instance

pg_dump $REMOTE_URL --format=tar > database.tar
pg_restore -p 5432 -h localhost -U $PGUSER -d fizi --no-owner --no-privileges database.tar

then switch back to your user (press ctrl + d)

Setup the bot

Clone the repo and copy the sample config

cd && git clone https://github.com/ItsLuuke/ProjectFizilionFork.git && cd ProjectFizilionFork
cp sample_config.env config.env

now edit the config (vim config.env or nano config.env) and add the vars

Install the requirements

python3 -m venv venv
source venv/bin/activate
python3 -m pip install -r requirements.txt
deactivate

Add a start script for ease of use

cat > run.sh << EOF
#!/bin/bash
source venv/bin/activate
python3 -m userbot
EOF
sudo chmod +x run.sh

test start the bot first and see if everything is fine

./run.sh

If there is error and the bot didnt start correctly, then fix then before continuing to the next step

If the bot starts fine then finish the pm2 setup

Strat the bot with pm2

pm2 start run.sh --name fizi

to make the bot start automatically on startup

pm2 save

to stop/start or restart or check logs

pm2 start fizi
pm2 stop fizi
pm2 restart fizi
pm2 logs fizi --lines 100 #or how many lines to check