ubuntu开机自启动
-
LinuxUbuntu20.04—添加开机启动(服务脚本)
系统启动时需要加载的配置⽂件
/etc/profile、/root/.bash_profile /etc/bashrc、/root/.bashrc /etc/profile.d/*.sh、/etc/profile.d/lang.sh /etc/sysconfig/i18n、/etc/rc.local(/etc/rc.d/rc.local)⼀、修改开机启动⽂件:/etc/rc.local(或者/etc/rc.d/rc.local)
# 1.编辑rc.local⽂件 [root@localhost ~]# vi /etc/rc.local # 2.修改rc.local⽂件,在 exit 0 前⾯加⼊以下命令。保存并退出。 /etc/init.d/mysqld start # mysql开机启动 /etc/init.d/nginx start # nginx开机启动 supervisord -c /etc/supervisor/supervisord.conf #supervisord开机启动 /bin/bash /server/scripts/test.sh >/dev/null 2>/dev/null # 3.最后修改rc.local⽂件的执⾏权限 [root@localhost ~]# chmod +x /etc/rc.local [root@localhost ~]# chmod 755 /etc/rc.local⼆、⾃⼰写⼀个shell脚本
将写好的脚本(.sh⽂件)放到⽬录 /etc/profile.d/ 下,系统启动后就会⾃动执⾏该⽬录下的所有shell脚本。三、通过chkconfig命令设置
# 1.将(脚本)启动⽂件移动到 /etc/init.d/或者/etc/rc.d/init.d/⽬录下。(前者是后者的软连接) mv /www/wwwroot/test.sh /etc/rc.d/init.d # 2.启动⽂件前⾯务必添加如下三⾏代码,否侧会提⽰chkconfig不⽀持。 #!/bin/sh 告诉系统使⽤的shell,所以的shell脚本都是这样 #chkconfig: 35 20 80 分别代表运⾏级别,启动优先权,关闭优先权,此⾏代码必须 #description: http server ⾃⼰随便发挥,此⾏代码必须 /bin/echo $(/bin/date +%F_%T) >> /tmp/test.log # 3.增加脚本的可执⾏权限 chmod +x /etc/rc.d/init.d/test.sh # 4.添加脚本到开机⾃动启动项⽬中。添加到chkconfig,开机⾃启动。 [root@localhost ~]# cd /etc/rc.d/init.d [root@localhost ~]# chkconfig --add test.sh [root@localhost ~]# chkconfig test.sh on # 5.关闭开机启动 [root@localhost ~]# chkconfig test.sh off # 6.从chkconfig管理中删除test.sh [root@localhost ~]# chkconfig --del test.sh # 7.查看chkconfig管理 [root@localhost ~]# chkconfig --list test.sh四、⾃定义服务⽂件,添加到系统服务,通过Systemctl管理
1.写服务⽂件:如nginx.service、redis.service、supervisord.service -
genostack平台开机自启:
部署应用分为两部分:docker启动服务,和cromwell,jar包
docker 容器启动使用 docker run --restart=always ...
cromwell启动方式:- 创建文件
/lib/systemd/system/cromwell.service
[Unit] Description=cromwell After=docker [Service] Type=forking ExecStart={{ project_root }}/genostack_project/cromwell/start_cromwell_local.sh Restart=always RestartSec=60 [Install] WantedBy=multi-user.target- 创建 start_cromwell_local.sh,注意:因为cromwell会依赖postgresql, 所以先启动数据库,在启动cromwell
#!/bin/bash docker run --restart=always -v /opt/app/genostack_project/postgresql_data:/var/lib/postgresql/data -e POSTGRES_PASSWORD=anneng@1235_Jike2015 -p 5435:5432 -d postgres:10 sleep 20s java -jar -Dconfig.file=/opt/app/genostack_project/cromwell/local.conf /opt/app/genostack_project/cromwell/cromwell-51.jar server >> /opt/app/genostack_project/cromwell/nohup.out 2>&1 &- 授权 sudo chmod +x start_cromwell_local.sh
- sudo systemctl daemon-reload
- systemctl enable springboot.service
- 创建文件