0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

termux起動時に色々動かす

0
Posted at

Termuxで、最近のサーバー環境に必須とも言えるssh/tmux/cloudflaredを自動起動するコード。
あらかじめそれらをpkg installしておいてください。

まず、.bashrcを開きます。

nano ~/.bashrc

既存コードの下にでも書いてください。

sshd

# --- tmux Auto-start/Attach ---
# Only run if we are in an interactive shell and NOT already inside tmux
if [[ -z "$TMUX" && $- == *i* ]]; then
    tmux attach-session -t default 2>/dev/null || tmux new-session -s default
fi

# --- Cloudflare Tunnel Auto-start ---
# Check if cloudflared is already running to avoid duplicate processes
if ! pgrep -x "cloudflared" > /dev/null; then
    echo "Starting Cloudflare Tunnel..."
    
    nohup cloudflared tunnel run --token 【トークン】 > /dev/null 2>&1 &
    
    disown
    echo "Cloudflare Tunnel is now running in the background."
fi

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?