在ubuntu早期版本以及18.04后的版本,还是支持在rc.local中进行操作开机自启。
1、编辑rc.local文件
cat <<EOF >/etc/rc.local
 #!/bin/sh -e
 # rc.local
 # This script is executed at the end of each multiuser runlevel.
 # Make sure that the script will "exit 0" on success or any other
 # value on error.
 # In order to enable or disable this script just change the execution
 # bits.
 # By default this script does nothing.
 /hangshu/run &
 exit 0
 EOF
注:在文件中添加要在开机时自动执行的命令(/hangshu/run )。请确保命令在exit 0之前。要在命令之后添加&符号以使其以后台模式运行。
2、授予rc.local文件可执行权限
root@firefly:~# chmod +x /etc/rc.local
注:重新启动系统,命令将会在系统启动时自动执行。