要設置服務在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替換為您要設置自啟動的其他服務名稱。