tgcf icon indicating copy to clipboard operation
tgcf copied to clipboard

How to run automatically the forwarding when launching service

Open superbonaci opened this issue 1 year ago • 1 comments

Each time I reboot the computer I have to do this:

cd ~/my-tgcf
source .venv/bin/activate
tgcf-web

That's easy. The problem comes because the forwarding is not started automatically. So I have to login to http://localhost:8501/Run, enter the password and click the red button Run. Is possible to have this Run be executed automatically each time I run the commands above?

superbonaci avatar Sep 17 '24 14:09 superbonaci

Run tgcf instead:

 Usage: tgcf [OPTIONS] MODE:{past|live}                                                             
                                                                                                    
 The ultimate tool to automate custom telegram message forwarding.                                  
 Source Code: https://github.com/aahnik/tgcf                                                        
 For updates join telegram channel @aahniks_code                                                    
 To run web interface run `tgcf-web` command.                                                       
                                                                                                    
╭─ Arguments ──────────────────────────────────────────────────────────────────────────────────────╮
*    mode      MODE:{past|live}  Choose the mode in which you want to run tgcf.                  │
[env var: TGCF_MODE]                          │                                  [default: None]                                                 │
[required]                                    ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Options ────────────────────────────────────────────────────────────────────────────────────────╮
--loud     -l        Increase output verbosity. [env var: LOUD]--version  -v        Show version and exit.                                                      │
--help               Show this message and exit.                                                 │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯

ℰ.ℊ.: tgcf live It will use the tgcf.config.json you already have.

Automate everything when system reboots, with systemd.

① Ensure your Linger is on: loginctl show-user ${USER} | grep Linger.  If no, enable it with: sudo loginctl enable-linger ${USER}.  Or, if no admin access, keep a session open with screen or tmux, and service should start as soon as you login.

② Create a script with your commands:

cat > ~/my-tgcf/my-tgcf.sh 

③ Create a systemd service file to run the script:

cat > ~/my-tgcf/my-tgcf.service 

④ Install the service: ln -s ~/my-tgcf/my-tgcf.service ~/.config/systemd/user/

⑤ Enable the service: systemctl --user enable my-tgcf

⑥ Start the service: Stop the instance you have running from tgcf-web, then: systemctl --user start my-tgcf

⑦ Profit?

scarlion1 avatar Dec 08 '24 08:12 scarlion1