• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
TRIGGERcmd
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

How do you install TRIGGERcmd on Raspberry pi with OpenWRT?

Raspberry Pi
2
19
1.4k
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R
    Russ @Scott Barton
    last edited by Russ Feb 27, 2021, 3:03 PM Feb 27, 2021, 3:01 PM

    @Scott-Barton, please try this.

    Make a /etc/init.d/tcmd file with these contents:

    #!/bin/sh /etc/rc.common
    
    START=35
    start() {
      /full/path/to/starttriggercmd
    }
    

    Then run this command to enable it so it will run /full/path/to/starttriggercmd during boot:

    /etc/init.d/tcmd enable
    

    In other words, I think the problem might be that you didn't specify the full path to the starttriggercmd script, or the problem might be that the you tried boot() and start_service() but I think it needs to be start().

    Russell VanderMey

    1 Reply Last reply Reply Quote 0
    • S
      Scott Barton
      last edited by Scott Barton Mar 8, 2021, 9:06 PM Mar 3, 2021, 7:59 PM

      @Russ I was able to get the service to start using OpenWRT. However when I use Alexa to issue commands, it says that it ran the command but doesn't seem to work (doesn't actually do what it was supposed to do). If I manually start the Triggercmd service from SSH and use Alexa to issue a command it works.

      89b67fd2-98af-4a69-8ceb-6a6cec9a4eff-image.png

      Here is the log:
      Thu Mar 4 10:36:23 2021 daemon.notice procd: /etc/rc.d/S95done: Running Linux daemon to run background tasks.
      Thu Mar 4 10:36:23 2021 daemon.notice procd: /etc/rc.d/S95done: Run installdaemon.sh to install the triggercmdagent daemon so it runs during boot
      Thu Mar 4 10:36:23 2021 daemon.notice procd: /etc/rc.d/S95done: Tokenfile: /root/.TRIGGERcmdData/token.tkn
      Thu Mar 4 10:36:23 2021 daemon.notice procd: /etc/rc.d/S95done: ComputerIDfile: /root/.TRIGGERcmdData/computerid.cfg
      Thu Mar 4 10:36:23 2021 daemon.notice procd: /etc/rc.d/S95done: Logging in with saved token to run background tasks.
      Thu Mar 4 10:36:24 2021 daemon.notice procd: /etc/rc.d/S95done: (node:3088) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
      Thu Mar 4 10:36:24 2021 daemon.notice procd: /etc/rc.d/S95done: (Use node --trace-warnings ... to show where the warning was created)
      Thu Mar 4 10:36:24 2021 daemon.notice procd: /etc/rc.d/S95done: Write backup completed.
      Thu Mar 4 10:36:25 2021 daemon.notice procd: /etc/rc.d/S95done:
      Thu Mar 4 10:36:25 2021 daemon.notice procd: /etc/rc.d/S95done:
      Thu Mar 4 10:36:25 2021 daemon.notice procd: /etc/rc.d/S95done: |> Now connected to https://www.triggercmd.com.
      Thu Mar 4 10:36:25 2021 daemon.notice procd: /etc/rc.d/S95done: ___/ For help, see: http://bit.ly/2q0QDpf
      Thu Mar 4 10:36:25 2021 daemon.notice procd: /etc/rc.d/S95done: (using sails.io.js node SDK @v1.2.1)
      Thu Mar 4 10:36:25 2021 daemon.notice procd: /etc/rc.d/S95done: Connected at: Thu Mar 04 2021 10:36:25 GMT-0500 (EST)
      Thu Mar 4 10:36:25 2021 daemon.notice procd: /etc/rc.d/S95done:
      Thu Mar 4 10:36:25 2021 daemon.notice procd: /etc/rc.d/S95done:
      Thu Mar 4 10:36:25 2021 daemon.notice procd: /etc/rc.d/S95done:
      Thu Mar 4 10:36:25 2021 daemon.notice procd: /etc/rc.d/S95done: Initiated command adds
      Thu Mar 4 10:36:25 2021 daemon.notice procd: /etc/rc.d/S95done: Initiated command removals
      Thu Mar 4 10:36:25 2021 daemon.notice procd: /etc/rc.d/S95done: { message: 'Subscribed to 5038e6811ca15100191cf7de!' }
      Thu Mar 4 10:36:25 2021 daemon.notice procd: /etc/rc.d/S95done: { message: 'Subscribed to 5038e6811ca15100191cf7de!' }
      Thu Mar 4 10:37:19 2021 daemon.notice procd: /etc/rc.d/S95done: { trigger: 'AdBlock', id: '503962d2b77e2b0019cf137a', params: 'off' }
      Thu Mar 4 10:37:19 2021 daemon.notice procd: /etc/rc.d/S95done: Running trigger: AdBlock Command: /scripts/adblock.sh off
      Thu Mar 4 10:37:20 2021 daemon.notice procd: /etc/rc.d/S95done: Reported: Command Ran

      R 1 Reply Last reply Mar 3, 2021, 11:47 PM Reply Quote 0
      • R
        Russ @Scott Barton
        last edited by Russ Mar 3, 2021, 11:48 PM Mar 3, 2021, 11:47 PM

        @Scott-Barton, I think the problem is your commands are set with "ground": "foreground" and they need to be "ground": "background" to run via the background service (aka daemon). Please check that in your /root/.TRIGGERcmdData/commands.json file.

        When you're running the agent manually, it's running in foreground mode, which explains why the commands work if you run the agent that way.

        Russell VanderMey

        S 1 Reply Last reply Mar 4, 2021, 3:29 PM Reply Quote 0
        • S
          Scott Barton @Russ
          last edited by Scott Barton Mar 4, 2021, 3:42 PM Mar 4, 2021, 3:29 PM

          @Russ I have the ground set to background in the /root/.TRIGGERcmdData/commands.json file. I did actually try changing it to foreground to see if it would work, but did not so I switched it back.

          cc3bb1de-5a20-4665-b9f8-d646c8f7de04-image.png

          Thanks for your help!

          R 1 Reply Last reply Mar 4, 2021, 11:58 PM Reply Quote 0
          • R
            Russ @Scott Barton
            last edited by Mar 4, 2021, 11:58 PM

            @Scott-Barton, are you saying you're seeing this in the log, but /scripts/adblock.sh off doesn't actually run?

            Thu Mar 4 10:37:19 2021 daemon.notice procd: /etc/rc.d/S95done: Running trigger: AdBlock Command: /scripts/adblock.sh off
            Thu Mar 4 10:37:20 2021 daemon.notice procd: /etc/rc.d/S95done: Reported: Command Ran
            

            Can you confirm it's not running by adding something like this at the top of your script, and check the /tmp/adblock.log file after triggering the command?

            echo /scripts/adblock.sh ran. >> /tmp/adblock.log
            

            Russell VanderMey

            1 Reply Last reply Reply Quote 0
            • S
              Scott Barton
              last edited by Scott Barton Mar 5, 2021, 4:07 PM Mar 5, 2021, 3:53 PM

              @Russ The log says it ran, but it doesn't do what it is supposed to do when the service is started automatically from the OpenWRT Local Startup script (/etc/rc.local). When I start the service from SSH using the exact same command that is in the startup script, it will run and do what it is supposed to do. However, if I close that SSH the service stops working. Both logs look exactly the same, but one actually executes and the other doesn't. I wonder if it is a permissions thing somehow?

              9bc5f411-c83d-4fa6-9221-3a371898c874-image.png

              ed93e998-dd07-4c75-84e6-efcc42537950-image.png

              R 1 Reply Last reply Mar 6, 2021, 1:19 AM Reply Quote 0
              • R
                Russ @Scott Barton
                last edited by Mar 6, 2021, 1:19 AM

                @Scott-Barton, that's good. Now we know the TRIGGERcmd agent is running your command because we see the log output from it. So now I think the problem is likely either that your present working directory is different when the script is running in that context, or there are different environment variables in that context.

                You could log your environment variables to that log file with a command like this at the top of your script:

                env >> /tmp/env.log
                

                You could log your present working directory to that log file with a command like this at the top:

                pwd >> /tmp/pwd.log
                

                Russell VanderMey

                S 1 Reply Last reply Mar 8, 2021, 4:02 PM Reply Quote 0
                • S
                  Scott Barton @Russ
                  last edited by Mar 8, 2021, 4:02 PM

                  @Russ said in How do you install TRIGGERcmd on Raspberry pi with OpenWRT?:

                  pwd >> /tmp/pwd.log

                  I put those lines in both my starttriggercmd script and my adblock script.

                  When starting TRIGGERcmd automatically from the OpenWRT startup script I get the following for ENV:
                  HLVL=3
                  HOME=/
                  TERM=linux
                  PATH=/usr/sbin:/usr/bin:/sbin:/bin
                  PWD=/

                  When I then run disableadblock command using Alexa I get the following for ENV:
                  SHLVL=5
                  HOME=/
                  NODE_TLS_REJECT_UNAUTHORIZED=0
                  TERM=linux
                  TCMD_COMPUTER_ID=5038e6811df15100191e57de
                  PATH=/usr/sbin:/usr/bin:/sbin:/bin
                  TCMD_COMMAND_ID=503962d2b77dfb0019ed137a
                  PWD=/gitrepo/TRIGGERcmd-Agent/src

                  If I then disable TRIGGERcmd from autostart and reboot and run it manually from SSH (FYI, I was within the /tmp directory when I ran it) I get the following for ENV:
                  USER=root
                  SHLVL=2
                  HOME=/root
                  OLDPWD=/root
                  SSH_TTY=/dev/pts/0
                  PS1=[\e]0;\u@\h: \w\a]\u@\h:\w$
                  ENV=/etc/shinit
                  VISUAL=nano
                  LOGNAME=root
                  TERM=xterm
                  PATH=/usr/sbin:/usr/bin:/sbin:/bin:/scripts
                  SHELL=/bin/ash
                  PWD=/tmp
                  EDITOR=nano

                  And then when I run the disableadblocker script using Alexa I get:
                  USER=root
                  SSH_CLIENT=192.168.2.2 51955 22
                  SHLVL=4
                  HOME=/root
                  OLDPWD=/root
                  SSH_TTY=/dev/pts/0
                  PS1=[\e]0;\u@\h: \w\a]\u@\h:\w$
                  ENV=/etc/shinit
                  VISUAL=nano
                  NODE_TLS_REJECT_UNAUTHORIZED=0
                  LOGNAME=root
                  TERM=xterm
                  TCMD_COMPUTER_ID=5038e6811df15100191e57de
                  PATH=/usr/sbin:/usr/bin:/sbin:/bin:/scripts
                  TCMD_COMMAND_ID=503962d2b77dfb0019ed137a
                  SHELL=/bin/ash
                  PWD=/gitrepo/TRIGGERcmd-Agent/src
                  SSH_CONNECTION=192.168.2.2 51955 192.168.2.1 22
                  EDITOR=nano

                  R 1 Reply Last reply Mar 9, 2021, 12:19 AM Reply Quote 0
                  • R
                    Russ @Scott Barton
                    last edited by Mar 9, 2021, 12:19 AM

                    @Scott-Barton said in How do you install TRIGGERcmd on Raspberry pi with OpenWRT?:

                    PATH=/usr/sbin:/usr/bin:/sbin:/bin:/scripts

                    I haven't seen your adblock.sh file yet, but by chance, does it try to run a script in the /script directory without using the full path (like script.sh instead of /scripts/script.sh)?

                    I noticed your /scripts folder got added to the PATH variable in the context where your adblock.sh script is working.

                    PATH=/usr/sbin:/usr/bin:/sbin:/bin:/scripts

                    Russell VanderMey

                    S 1 Reply Last reply Mar 23, 2021, 6:17 PM Reply Quote 0
                    • S
                      Scott Barton @Russ
                      last edited by Mar 23, 2021, 6:17 PM

                      @Russ yes it's not using the full directory. Here is the adblock.sh script:

                      #/bin/ash
                      
                      echo running /scripts/adblock.sh now >> /tmp/adblock.log
                      env >> /tmp/adenv.log
                      pwd >> /tmp/adpwd.log
                      
                      case "$1" in
                        "on")
                          enableadblock
                          echo  /scripts/adblock.sh on ran >> /tmp/adblock.log
                          ;;
                        "off")
                          disableadblock
                          echo  /scripts/adblock.sh off ran >> /tmp/adblock.log
                      
                          ;;
                        *)
                          echo "Run this with on or off as the parameter."
                          exit 1
                          ;;
                      
                      1 Reply Last reply Reply Quote 0
                      • S
                        Scott Barton
                        last edited by Mar 23, 2021, 6:32 PM

                        I just updated the scripts that TRIGGERcmd runs to have full paths, and now it works, thanks!

                        1 Reply Last reply Reply Quote 1
                        • tuicemenT tuicemen moved this topic from Instructions on Jan 31, 2022, 12:16 PM
                        • First post
                          Last post