Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run automatically the forwarding when launching service #621

Open
superbonaci opened this issue Sep 17, 2024 · 1 comment
Open

How to run automatically the forwarding when launching service #621

superbonaci opened this issue Sep 17, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@superbonaci
Copy link

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 superbonaci added the bug Something isn't working label Sep 17, 2024
@scarlion1
Copy link

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 <<␃
#!/usr/bin/env bash
cd ~/my-tgcf
source .venv/bin/activate
tgcf live
␃
chmod +x ~/my-tgcf/my-tgcf.sh

③ Create a systemd service file to run the script:

cat > ~/my-tgcf/my-tgcf.service <<␃
[Unit]
Description=my-tgcf
After=network.target

[Install]
WantedBy=default.target

[Service]
# use the absolute path of the shell script in your server
ExecStart=/home/superbonaci/my-tgcf/my-tgcf.sh
␃

④ 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants