It can be combined with systemctl and tmux for script startup, it is very convenient tmux a can go back to the background to see real-time logs
Here's my server startup script for reference, tmux is too convenient for me!
#!/bin/zsh
# Define the function that sends the command
send_command() {
tmux send -t $1 $2 Enter
}
# Close and delete the tmux session named "db".
tmux kill-session -t "db"
# Create a tmux session named "db".
tmux new -t "db" -d
tmux rename-window -t "db:1" "mongod"
# n the "mongod" pane, execute the command
send_command "mongod" "cd /home/web/MongoDB/bin/ && ./mongod --config ./mongo.conf"
# Creating Horizontally Split Panes
tmux split-window -h -t "db:mongod" -d
tmux select-window -t "db:mongod"
tmux select-pane -t "2"
# Close and delete the tmux session named "nodebb".
tmux kill-session -t "nodebb"
# Create a tmux session called "nodebb".
tmux new -t "nodebb" -d
tmux rename-window -t "nodebb:1" "grunt"
# Execute the command in the "grunt" pane.
send_command "nodebb" "cd /home/web/NodeBB/ && ./nodebb slog"
# Creating Horizontally Split Panes
tmux split-window -h -t "nodebb:grunt" -d
tmux select-window -t "nodebb:grunt"
tmux select-pane -t "2"
exit 0
[Unit]
Description=Startup Script
After=network.target
[Service]
Type=forking
Environment=TERM=xterm-256color
ExecStartPre=/usr/bin/zsh -c 'source $HOME/.zshrc'
ExecStart=/root/auto_script/startup.sh
User=root
Group=root
[Install]
WantedBy=multi-user.target