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.
    • Scott BartonS
      Scott Barton
      last edited by Scott Barton

      @Russ I can't get it to work. I created an initscript in /etc/init.d and and enabled it but can't seem to get it to work.

      #!/bin/sh /etc/rc.common

      START=35
      boot() {
      starttriggercmd
      }

      Also tried
      #!/bin/sh /etc/rc.common

      START=35
      start_service() {
      starttriggercmd
      }

      strarttriggercmd is a command I wrote to start the daemon.js and if I run it from the prompt it works. It basically just runs this:
      node /gitrepo/TRIGGERcmd-Agent/src/daemon.js --run /root/.TRIGGERcmdData

      RussR 1 Reply Last reply Reply Quote 0
      • RussR
        Russ @Scott Barton
        last edited by Russ

        @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
        • Scott BartonS
          Scott Barton
          last edited by Scott Barton

          @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

          RussR 1 Reply Last reply Reply Quote 0
          • RussR
            Russ @Scott Barton
            last edited by Russ

            @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

            Scott BartonS 1 Reply Last reply Reply Quote 0
            • Scott BartonS
              Scott Barton @Russ
              last edited by Scott Barton

              @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!

              RussR 1 Reply Last reply Reply Quote 0
              • RussR
                Russ @Scott Barton
                last edited by

                @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
                • Scott BartonS
                  Scott Barton
                  last edited by Scott Barton

                  @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

                  RussR 1 Reply Last reply Reply Quote 0
                  • RussR
                    Russ @Scott Barton
                    last edited by

                    @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

                    Scott BartonS 1 Reply Last reply Reply Quote 0
                    • Scott BartonS
                      Scott Barton @Russ
                      last edited by

                      @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

                      RussR 1 Reply Last reply Reply Quote 0
                      • RussR
                        Russ @Scott Barton
                        last edited by

                        @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

                        Scott BartonS 1 Reply Last reply Reply Quote 0
                        • Scott BartonS
                          Scott Barton @Russ
                          last edited by

                          @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
                          • Scott BartonS
                            Scott Barton
                            last edited by

                            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
                            • First post
                              Last post