刷新linux开机启动脚本
时间: 2023-11-20 10:06:43 浏览: 35
Linux 系统中可以使用脚本在开机时自动启动某些程序或服务。常用的开机启动脚本位于 /etc/init.d/ 目录下,可以使用 chkconfig 命令来管理这些脚本的开机启动状态。
例如,要让 Apache 服务在开机时自动启动,可以使用以下命令:
```
sudo chkconfig httpd on
```
可以使用 `systemctl enable xxx.service` 命令来开启开机启动服务。
例如:
```
sudo systemctl enable httpd.service
```
此外还可以在 `/etc/rc.local` 文件中添加启动命令来实现开机启动。
相关问题
linux 开机启动脚本
Linux 开机启动脚本可以通过以下步骤来创建:
1. 编写启动脚本:在 /etc/init.d 目录下创建一个新文件,例如 myservice,然后在该文件中编写启动脚本。
2. 添加执行权限:为启动脚本添加执行权限,使用 chmod 命令,如:sudo chmod +x /etc/init.d/myservice。
3. 将脚本添加到启动项:使用 update-rc.d 命令将脚本添加到启动项中,如:sudo update-rc.d myservice defaults。
4. 启动服务:使用 service 命令启动服务,如:sudo service myservice start。
下面是一个示例启动脚本:
```
#!/bin/sh
### BEGIN INIT INFO
# Provides: myservice
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop myservice
### END INIT INFO
case $1 in
start)
echo "Starting myservice"
# command to start the service
;;
stop)
echo "Stopping myservice"
# command to stop the service
;;
restart)
echo "Restarting myservice"
# command to restart the service
;;
*)
echo "Usage: /etc/init.d/myservice {start|stop|restart}"
exit 1
;;
esac
exit 0
```
在这个示例中,你需要将 # command to start/stop/restart the service 替换为实际的启动/停止/重启命令。同时,你需要将 myservice 替换为你实际的服务名称。
linux开机启动脚本
Linux 系统中可以使用脚本在开机时自动启动某些程序或服务。常用的开机启动脚本位于 /etc/init.d/ 目录下,可以使用 chkconfig 命令来管理这些脚本的开机启动状态。
例如,要让 Apache 服务在开机时自动启动,可以使用以下命令:
```
sudo chkconfig httpd on
```
可以使用 `systemctl enable xxx.service` 命令来开启开机启动服务。
例如:
```
sudo systemctl enable httpd.service
```
此外还可以在 `/etc/rc.local` 文件中添加启动命令来实现开机启动。