<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[ubuntu开机自启动]]></title><description><![CDATA[<h2>LinuxUbuntu20.04—添加开机启动（服务脚本）</h2>
<h3>系统启动时需要加载的配置⽂件</h3>
<pre><code>/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）
</code></pre>
<p dir="auto">⼀、修改开机启动⽂件：/etc/rc.local（或者/etc/rc.d/rc.local）</p>
<pre><code># 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 &gt;/dev/null 2&gt;/dev/null
# 3.最后修改rc.local⽂件的执⾏权限
[root@localhost ~]# chmod +x  /etc/rc.local
[root@localhost ~]# chmod 755 /etc/rc.local
</code></pre>
<p dir="auto">⼆、⾃⼰写⼀个shell脚本<br />
将写好的脚本（.sh⽂件）放到⽬录 /etc/profile.d/ 下，系统启动后就会⾃动执⾏该⽬录下的所有shell脚本。</p>
<p dir="auto">三、通过chkconfig命令设置</p>
<pre><code># 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) &gt;&gt; /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
</code></pre>
<p dir="auto">四、⾃定义服务⽂件，添加到系统服务，通过Systemctl管理<br />
1.写服务⽂件：如nginx.service、redis.service、supervisord.service</p>
]]></description><link>http://an.forum.genostack.com/topic/654/ubuntu开机自启动</link><generator>RSS for Node</generator><lastBuildDate>Sat, 13 Jun 2026 12:33:15 GMT</lastBuildDate><atom:link href="http://an.forum.genostack.com/topic/654.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 16 May 2022 08:45:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to ubuntu开机自启动 on Tue, 05 Jul 2022 03:45:15 GMT]]></title><description><![CDATA[<p dir="auto">genostack平台开机自启：<br />
部署应用分为两部分：docker启动服务，和cromwell，jar包<br />
docker 容器启动使用 docker run --restart=always ...<br />
cromwell启动方式：</p>
<ol>
<li>创建文件<br />
/lib/systemd/system/cromwell.service</li>
</ol>
<pre><code>[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
</code></pre>
<ol start="2">
<li>创建 start_cromwell_local.sh，注意：因为cromwell会依赖postgresql, 所以先启动数据库，在启动cromwell</li>
</ol>
<pre><code>#!/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 &gt;&gt; /opt/app/genostack_project/cromwell/nohup.out 2&gt;&amp;1 &amp;
</code></pre>
<ol start="3">
<li>授权  sudo chmod +x start_cromwell_local.sh</li>
<li>sudo systemctl daemon-reload</li>
<li>systemctl enable springboot.service</li>
</ol>
]]></description><link>http://an.forum.genostack.com/post/1648</link><guid isPermaLink="true">http://an.forum.genostack.com/post/1648</guid><dc:creator><![CDATA[zhanglu]]></dc:creator><pubDate>Tue, 05 Jul 2022 03:45:15 GMT</pubDate></item></channel></rss>