添加启动服务
2025/1/9原创小于 1 分钟约 143 字
1. 创建服务脚本
/etc/systemd/system/my_service.service
[Unit]
Description=My Custom Service
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/my_service_script.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
2. 创建执行脚本
/usr/local/bin/my_service_script.sh
#!/bin/bash
# Your custom service logic here
echo "My custom service is running"
3. 设置脚本可执行权限
chmod +x /usr/local/bin/my_service_script.sh
4. 重新加载 systemd 管理器配置
systemctl daemon-reload
5. 启动服务
systemctl start my_service
6. 设置开机启动
systemctl enable my_service