ubuntu开机自启动脚本

2024-01-07 20:30:09

20.04及以上开机启动

开机启动服务脚本 autostart.service

[Unit]
Description=hdcollectapp auto start
After=network-online.target
 
[Service]
ExecStart=/xxx/xxx.sh
 
[Install]
WantedBy=multi-user.target

服务部署

#!/bin/bash

function service_install(){
    #参数从1开始  $1 ${10}
    #参数个数     $#
    #参数字符串   $*
    SVR=$1
    SRV_PATH="./${SVR}"
	echo ${SVR}
	sudo chmod 777 ${SRV_PATH}
	sudo cp -f ${SRV_PATH} /etc/systemd/system
	sudo systemctl daemon-reload
	sudo systemctl enable ${SVR}
	sudo systemctl start ${SVR}
}
SERVICE_LIST=("xxx1.service" "xxx2.service")
for SVR in ${SERVICE_LIST[@]}; 
do
	service_install SVR
done
 
停止开机启动
sudo systemctl disable ${SVR}

文章来源:https://blog.csdn.net/littleleafboy/article/details/135392991
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。