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

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

Open
NightfallAlicorn opened this issue Nov 24, 2019 · 6 comments

Comments

@NightfallAlicorn
Copy link

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.

@termux termux deleted a comment from SDRausty Jan 1, 2020
@termux termux deleted a comment from waltervetrivel44 Jan 1, 2020
@Grimler91
Copy link
Member

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

@NightfallAlicorn
Copy link
Author

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.

@BlueMax
Copy link

BlueMax commented Feb 6, 2020

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).

@erkkkkkkkkk
Copy link

Task#44

@pwqw
Copy link

pwqw commented Oct 20, 2021

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?

@ShaKabosh
Copy link

ShaKabosh commented Oct 6, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants