1.编辑.desktop脚本放到/etc/xdg/autostart/目录下 ,进入桌面后执行
[Desktop Entry]
Version=1.0
Name=kkm
Exec=/home/hy/kkm.sh#这是那个可执行程序所在完整路径,如果程序有附加输入参数,也可以跟在后面添加,并用空格隔开
StartupNotify=false
NoDisplay=true
Type=Application
Categories=System;Utility;Archiving;
分2种级别,用户级别和系统级别
- 用户特定:
$XDG_CONFIG_HOME/autostart
(默认为~/.config/autostart
) - 系统范围:
$XDG_CONFIG_DIRS/autostart
(默认为 {{ic|/etc/xdg/autostart})
2,创建脚本,复制或者超链接到/etc/init.d/目录下(update-rc.d在ubuntu使用,centos 8.4中没有)
chmod +x kkm.sh
update-rc.d kkm.sh defaults 99 #增加到启动系统启动项中
update-rc.d -f kkm.sh remove #移除
arm开发板启动https的webapi服务时,会提示ssl故障,x86需要验证
3,systemctl启动,将编写好的sh脚本放到/etc/systemd/system目录,或者放在/usr/lib/systemd/system目录,有系统(system)和用户(user)之分
[Unit]
Description=kkm
After=network.service
[Service]
Type=simple
ExecStart=/home/hy/kkm.sh
Restart=always
RestartSec=10
PrivateTmp=true
[Install]
WantedBy=multi-user.target
参考以上脚本编写,脚本名字定义为kkm.service,之后放入 /etc/systemd/system目录,执行如下命令
systemctl enable kkm.service # 在开机时启用一个服务
systemctl daemon-reload #重新加载systemd(一般修改完配置文件执行该命令使配置生效)
sysetmctl详细配置参考https://blog.csdn.net/h394600493/article/details/120034611
4,chkconfig 已经不被推荐使用了
chkconfig --add 服务名称
chkconfig -leve 启动级别 服务名 on (说明,3级别代表在命令行模式启动,5级别代表在图形界面启动,on表示开启)
chkconfig -leve 启动级别 服务名 off
on表示开启,off表示关闭
5,/etc/rc.local目录中放启动脚本,不被推荐使用
6,crontab(类似于windows的任务计划服务)
在系统/etc/crontab目录中新增一行记录,例如:8 10 * * * root /homt/hy/kkm.sh (表示每天的10点8分使用root权限执行kkm.sh)
7,在文件/etc/profile中加入执行代码,在登录系统时执行
8,在/etc/profile.d/目录中加入执行脚本文件(后缀必须是.sh),在登录系统时执行
9,在/home/user/.profile中加入执行代码,只在user特定用户登录系统时执行