service开机启动项设置

我们用户级别程序启动需要一个依赖网络,驱动等加载初始化,所以要在一个启动级别非常靠后的位置,他们建议在rc.local中启动,这一个在他们的启动时序中是最后的级别,因此改动如下:

 还有一个rc-local.service的文件,一般是systemctl start/enable rc-local使用,/etc/systemd/system下的service一般是链接到/lib/systemd/system下面的软连接,所以还要创建:

ln -s /lib/systemd/sytem/rc-local.service /etc/systemd/sytem/rc-local.service
rc-local.service文件内容
#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

[Install]
WantedBy=multi-user.target
alias=rc-local.service

/etc/init.d/rc.local里面的内容(start_app.sh是我们内容)

#!/bin/sh
echo "~~~~~tztek init~~~~~"
/usr/sbin/mwwatchdog > /dev/null &
#add user starup
sleep 3 && cd /data/gac && sh start_app.sh &

  

  

posted @ 2023-06-06 20:41  hitzzq  阅读(79)  评论(0编辑  收藏  举报