【创龙TL570x-EVM】建立启动服务——打印helloworld
<p>【前言】有些服务或者程序需要在开机时就自己动启用的程序,需要加入到启动服务中。今天根据教程演示如何将开机打印hello world。</p><p>1、在前面目录下新建一个 helloword.sh的文件:</p>
<p> 输入如下内容:</p>
<p> 保存退出。</p>
<p>3、创建服务:<span style="font-size:12pt"><span style="font-family:宋体"><span style="color:#000000">进入文件系统</span></span></span><span style="font-size:12pt"><span style="font-family:Calibri"><span style="color:#000000">“/lib/systemd/system/”</span></span></span><span style="font-size:12pt"><span style="font-family:宋体"><span style="color:#000000">目录,新建一个自启动的 </span></span></span><span style="font-size:12pt"><span style="font-family:Calibri"><span style="color:#000000">systemd </span></span><span style="font-family:宋体"><span style="color:#000000">服务配置文件</span></span><span style="font-family:Calibri"><span style="color:#000000">helloworld.service</span></span></span><span style="font-size:12pt"><span style="font-family:宋体"><span style="color:#000000">。</span></span></span></p>
<p>输入如下内容:</p>
<p> <span style="font-size:12pt"><span style="font-family:宋体"><span style="color:#000000">其中 </span></span></span><span style="font-size:12pt"><span style="font-family:Calibri"><span style="color:#000000">Description </span></span></span><span style="font-size:12pt"><span style="font-family:宋体"><span style="color:#000000">为 </span></span></span><span style="font-size:12pt"><span style="font-family:Calibri"><span style="color:#000000">systemd </span></span></span><span style="font-size:12pt"><span style="font-family:宋体"><span style="color:#000000">服务的简短描述,</span></span></span><span style="font-size:12pt"><span style="font-family:Calibri"><span style="color:#000000">ExecStartPre </span></span></span><span style="font-size:12pt"><span style="font-family:宋体"><span style="color:#000000">为 </span></span></span><span style="font-size:12pt"><span style="font-family:Calibri"><span style="color:#000000">systemd </span></span></span><span style="font-size:12pt"><span style="font-family:宋体"><span style="color:#000000">服务的打印信息, </span></span></span></p>
<div><span style="font-size:12pt"><span style="font-family:Calibri"><span style="color:#000000">ExecStart </span></span></span><span style="font-size:12pt"><span style="font-family:宋体"><span style="color:#000000">为启动当前服务的命令。</span></span></span></div>
<p> 保存后退出。</p>
<p>4、输入服务生效命令:<span style="font-size:12pt"><span style="font-family:Calibri"><span style="color:#000000">systemctl -f enable /lib/systemd/system/helloworld.service</span></span></span></p>
<div><span style="font-size:12pt"><span style="font-family:宋体"><span style="color:#000000">重新启动 </span></span></span><span style="font-size:12pt"><span style="font-family:Calibri"><span style="color:#000000">Linux </span></span></span><span style="font-size:12pt"><span style="font-family:宋体"><span style="color:#000000">系统后,</span></span></span><span style="font-size:12pt"><span style="font-family:Calibri"><span style="color:#000000">systemd </span></span></span><span style="font-size:12pt"><span style="font-family:宋体"><span style="color:#000000">服务开启后就会自动执行 </span></span></span><span style="font-size:12pt"><span style="font-family:Calibri"><span style="color:#000000">helloworld.sh </span></span></span><span style="font-size:12pt"><span style="font-family:宋体"><span style="color:#000000">脚本的内容, </span></span></span></div>
<div><span style="font-size:12pt"><span style="font-family:宋体"><span style="color:#000000">系统打印信息如下图所示:</span></span></span></div>
<div> 【总结】学习了三步,新建启动文件,新建启动服务文件,生效服务命令。</div>
页:
[1]