How do you install TRIGGERcmd on Raspberry pi with OpenWRT?
-
I think that worked, thanks!
-
How do I create commands from CLI? The instructions say to use GUI Command Editor via the tray icon, but I'm running headless mode. Thanks!
EDIT: Found it. Need to edit /root/.TRIGGERcmdData/commands.json
Here are examples: https://github.com/FYDesktop/triggercmd-commands/blob/master/commands.json -
Also I can't find installdaemon.sh to get it to run in background on boot.
-
@Russ Having an installing and getting the daemon running.
ran .src/installdaemon.sh and got installdaemon.sh not found even though I can see that it is there:
I then opened installdaemon.sh to run the code manually. I verified that node.js is installed.
So skipped that and then I ran the bottom section of code in installdaemon.sh and got the following errors:
systemctl and systemmd are not installed for OpenWRT.
TIA.
Scott
-
@Scott-Barton, you should able to create an initscript. I wouldn't worry about whether the agent is running in foreground or background mode. It doesn't really matter in your case, but just make sure if you run it in foreground mode, your commands in your commands.json file have "ground": "foreground".
-
@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.commonSTART=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 -
@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().
-
@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.
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: (Usenode --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 -
@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.
-
@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.
Thanks for your help!
-
@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
-
@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?
-
@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
-
@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/srcIf 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=nanoAnd 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 -
@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
-
@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 ;;
-
I just updated the scripts that TRIGGERcmd runs to have full paths, and now it works, thanks!
-