gogos 默认是 3000端口,如果你本身已经有了其他WEB服务,比如apache,当然不可能同时占用80端口,这时候就可以利用apapche的proxy功能。如果你是apt-get 安装 的apache,就方便了,debian/ubuntu 都支持a2ensiate,a2enmod这样的小脚本。你只要打开a2enmod proxy proxy_http就行了,然后新建一个site加入以下配置
XML/HTML代码
- <VirtualHost *:80>
- ServerAdmin test@test.com
- ServerName yoursitename
- ProxyRequests off
- ProxyPass / http://127.0.0.1:3000/
- ProxyPassReverse / http://127.0.0.1:3000
- <Proxy *>
- Order Deny,Allow
- Allow from all
- </Proxy>
- ErrorLog ${APACHE_LOG_DIR}/yoursitename.log
- LogLevel warn
- </VirtualHost>
是不是很简单,这时候你用supervisor启动后就可以通过WEB访问了.不过这时候有具小缺点,那就是如果你killall gogs进程的话,你会发现再也启动不了了.看启动的LOG会告诉你3000端口被占用,用netstat -an|grep 3000,发现有N个进程都是在CLOSE_WAIT的情况,这时候用: echo $(netstat -anp|grep 127.0.0.1:3000 |awk '{print $7}') 发现,全是apache2占着这些进程.
怀疑刚才在强杀gogs进程的时候,apache因为开着proxy导致刚刚向3000端口发起请求就挂起,导致异常关闭所以一直卡住(以前用nginx的做反代的时候也有类似问题,只要客户机挂了,nginx必须 重启),所以我重启了一下apache,立刻发现gogs启动成功.
至此,如果要 重启gogs最好是/etc/init.d/supervisor restart ,如果不正常就再重启一下apache...
OK,问题全部解决
在gogs的release包中,linux_amd64.zip这个包里,scripts目录下没有start.sh这个文件,因此在 执行./scripts/gogs_supvisor.sh文件的时候会直接后/usr/local/bin/gogs_start文件不存在
打开这个gogs_supvisor.sh文件后,发现他会判断/usr/local/bin/gogs_start文件是否存在,如果不存在就将./scripts/start.sh文件复制 过去并改为为gogs_start
然而,scripts目录下并没有这个start.sh文件,这个问题在官方的issue中已经提出并有解决方案:https://github.com/gogits/gogs/issues/1198
解决方案就是:
XML/HTML代码
- oh man sorry for that.
-
- I would suggest install supervisor as init.d somehow doesn't worked for me after trying lot of diffrent combinations. to do that,
-
- sudo apt-get -y install supervisor
-
- and edit its file via
-
- sudo nano /etc/supervisor/supervisord.conf
-
- [program:gogs]
- directory=/home/git/go/src/github.com/gogits/gogs/
- command=/home/git/go/src/github.com/gogits/gogs/gogs web
- autostart=true
- autorestart=true
- startsecs=10
- stdout_logfile=/var/log/gogs/stdout.log
- stdout_logfile_maxbytes=1MB
- stdout_logfile_backups=10
- stdout_capture_maxbytes=1MB
- stderr_logfile=/var/log/gogs/stderr.log
- stderr_logfile_maxbytes=1MB
- stderr_logfile_backups=10
- stderr_capture_maxbytes=1MB
- environment = HOME="/home/git", USER="git"
-
- change directory's to match your installation and user to your git user. and restart the supervisor via,
- sudo service supervisor restart
-
- that's all you need to make gogs start automatically on boot.
看上述内容,修改一下supervisor的配置,加入gogs的配置,注意修改成你自己的路径即可