1.创建一个自定义的服务
sudo vi /etc/systemd/system/custom-shutdown.service
编辑
[Unit]
Description=Custom shutdown service
After=network.target[Service]
Type=simple
ExecStart=/bin/bash /path/to/your/script.sh[Install]
WantedBy=multi-user.target
重启
sudo systemctl daemon-reload
启动服务
sudo systemctl enable custom-shutdown.service
如果脚本里有sudo
sudo visudo
yourusername ALL=(ALL) NOPASSWD: /path/to/handle_power_button.sh
本文详细介绍了如何在Linux系统中创建一个名为custom-shutdown.service的自定义服务,包括编辑服务文件、配置重启和启动步骤,以及处理使用sudo权限的情况。
538

被折叠的 条评论
为什么被折叠?



