要设置服务在Ubuntu系统开机时自动启动,可以按照以下步骤进行操作:
sudo nano /etc/init.d/nginx
#!/bin/bash
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start nginx on boot
# Description: Start nginx on boot
### END INIT INFO
# Your service start command
start() {
# Start service command
}
# Your service stop command
stop() {
# Stop service command
}
# Your service restart command
restart() {
# Restart service command
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit 0
sudo chmod +x /etc/init.d/nginx
sudo update-rc.d nginx defaults
sudo reboot
这样,服务就会在系统开机时自动启动。您可以将上述步骤中的nginx替换为您要设置自启动的其他服务名称。