There are a lot of ways to start booting under Linux , and here I use the way I write shell commands in /etc/rc.local .
Here is my actual operation as an example, many places need to crossing themselves to adjust the information Oh!
1. In the /etc/rc.local file, add the script that you want to execute.
For example, what I'm going to do now is a script that starts with the Golang project:
Ficowlogpath= "/home/ficow/autolaunchlog.txt" #launch ficow ' s blog servercd/home/ficow/ficowblog/src #进入到目录. serverautorun.sh #执行Golang项目启动脚本echo "Ficowblog server autolaunched: ' Date '" >> $ficowLogPath #启动信息记录到/home/ Ficow/autolaunchlog.txt
Then save the exit.
There may be problems with rc.local not being executed. If so, the permissions to modify the rc.local file are executable!
chmod +x rc.local
2. Adjust the Golang project startup script (./serverautorun.sh)
#! /bin/bashexport Gopath=/home/ficow/gopath: ' CD. ; PWD ' echo ' Gopath: $GOPATH "Export Goroot=/home/ficow/goecho" Goroot: $GOROOT "path= $PATH: $HOME/bin:usr/local/git/bin: $GOROOT/bin: $GOPATH/bin:echo "PATH: $PATH" (Go run main.go >>/home/ficow/ficowblog/src/bloglog.txt 2>&1 &) echo "* * * Server reboot complete! ***"
Note: Since these scripts were executed as Su at startup, my gopath and goroot are not configured for Su,
So here I made the adjustment so that Su can know where gopath and goroot are, so that when the go run is executed, the error will not be made.
3. Permissions to modify the./serverautorun.sh file are executable:
chmod +x./serverautorun.sh
4. Restart the server. When you connect to the past with SSH, the program is already running, and the record has been exported to the log file.
5. The following is my deployment of the program corresponding to the blog, crossing want to see?
Click to go directly to my blog (ficow.cn)
Reference article:
Linux Add Boot Script example
Linux boot script or service
CentOS 6.5 rc.local Boot does not perform a solution to a case
Ways to let processes run in the background in Linux
Ficow Original, reproduced please specify the source: http://www.cnblogs.com/ficow/p/6681473.html
Golang the blog daemon on Linux CentOS 6.5 server boot