termux-boot icon indicating copy to clipboard operation
termux-boot copied to clipboard

[Feature Request] Allow Termux:Boot to run a Termux "session" instead of an invisible "task"

Open NightfallAlicorn opened this issue 6 years ago • 6 comments

When Termux:Boot runs a script and an unknown error occurs. There's no way for the user to see what the issue is on the log. From my experience outputting the command log to a file isn't reliable such as node ~/path/to/file/index.js >> log.txt.

The script runs fine when I run it in Termux but the auto script with the exact same command says it's running but it really isn't.

NightfallAlicorn avatar Nov 24 '19 14:11 NightfallAlicorn

You probably want to do &> /data/data/com.termux/files/home/log.txt. &> captures the error stream as well and you probably want to use an absolute path so that you know where the log ends up

Grimler91 avatar Jan 01 '20 10:01 Grimler91

The only concern I have with this method is that it will reduce the write cycles of my android's internal memory. Say if a script goes out of control with the log writes without the user being aware. But this should help users keep some track of what's going on.

NightfallAlicorn avatar Jan 01 '20 23:01 NightfallAlicorn

I use it as well in combination with set -x for more verbose output:

#!/data/data/com.termux/files/usr/bin/bash
set -x
exec &> /mnt/ramdisk/log.txt
...

Size-limited ramdisk:

mount -t tmpfs -o size=100M tmpfs /mnt/ramdisk

I actually spawn multiple size-limited ramdisks at early-boot to overlay several /data/data/*/{tmp,cache} folders (browser cache etc) to save write cycles. Plus a large one for temporary stuff (downloads etc).

BlueMax avatar Feb 06 '20 23:02 BlueMax

Task#44

erkkkkkkkkk avatar May 02 '21 05:05 erkkkkkkkkk

mount -t tmpfs -o size=100M tmpfs /mnt/ramdisk

I actually spawn multiple size-limited ramdisks at early-boot to overlay several /data/data/*/{tmp,cache} folders (browser cache etc) to save write cycles. Plus a large one for temporary stuff (downloads etc).

Interesting approach.

But what if the phone is not rooted?

pwqw avatar Oct 20 '21 04:10 pwqw

Here's a bit of a fix I found for this: Uncomment the line

# allow-external-apps = true

in ~/.termux/termux.properties, so it looks like this:

allow-external-apps = true

Now, create a file in ~/.termux/boot/ for your shell script containing the below text:

am startservice --user 0 -n com.termux/com.termux.app.RunCommandService \
-a com.termux.RUN_COMMAND \
--es com.termux.RUN_COMMAND_PATH '<CMD_PATH>' \
--esa com.termux.RUN_COMMAND_ARGUMENTS '<ARGS>' \
--es com.termux.RUN_COMMAND_WORKDIR '<WORKING_DIR>' \
--ez com.termux.RUN_COMMAND_BACKGROUND 'false' \
--es com.termux.RUN_COMMAND_SESSION_ACTION '0'

Substitute <CMD_PATH> for an absolute path to the binary, <ARGS> for a comma-separated list of arguments, and <WORKING_DIR> for the working directory. When this script runs, it calls an intent to open a session. It is important that RUN_COMMAND_SESSION_ACTION is set to '0' which opens the session in the app when the intent is sent, as otherwise (in my experience, at least), Termux will not run the command until the session is switched to.

ShaKabosh avatar Oct 06 '23 05:10 ShaKabosh