Yes, it is not a long memory after doing it countless times. Yesterday I stepped on it again; the startup script written on ubuntu does not execute, it is only a problem of executable permissions and user permissions, and wasted another morning;
Do some work automatically when unbuntu starts. The best practice is:
At this time you need to use ubuntu's upstart mechanism
To put it simply, this is a script like this:
123 | start on startuptaskexec /path/to/command |
---|
Save it as a taskxxx.conf file and place it under the /etc/init directory (this will be started with root user authority when booting);
Or save as ~/.config/upstart (this will start with the current user rights at boot time)
You need to use the systemd service, which we wrote about popular science articles before:
https://happy123.me/blog/2016/08/22/how-to-write-standard-startup-script/
1 | sudo nano /etc/rc.local |
---|
Add the executed command, don’t forget to add exit at the end
12 | /opt/tmux.shexit 0 |
---|
Increase executable permissions
1 | sudo chmod +x /etc/rc.local |
---|
note:
Modify the current user:
1 | nano ~/.bashrc |
---|
Effective for all users:
1 | nano ~/etc/profile |
---|
Just start a tmux session in /etc/rc.local and execute the commands you want to run in it; simple and rude and effective
Here is a template:
1234567891011121314151617181920 | #! /bin/bash# description "Start Tmux"# Sleep for 5 seconds. If you are starting more than one tmux session# "at the same time", then make sure they all sleep for different periods# or you can experience problems/bin/sleep 5# Ensure the environment is availablesource ~/.bashrc# Create a new tmux session named newscrawler../usr/bin/tmux new-session -d -s bitcoin# ...and control the tmux session (initially ensure the environment# is available, then run commands)# /usr/bin/tmux send-keys -t bitcoincash:0 "source ~/.bashrc" C-mtmux new-window -n console -t bitcoin/bin/sleep 3/usr/bin/tmux send-keys -t bitcoin:0 "cd /opt/bitcoin && ./startbitcoind.sh" C-m/bin/sleep 3/usr/bin/tmux send-keys -t bitcoin:1 "cd /opt/bitcoin && ./checkwallet start" C-m |
---|
Recommended Posts