我的QNAP上后来安装的一个类github网站Gitea一直无法开机自启动。怀疑是因为启动顺序在Qgit之前的缘故。于是研究了一番QNAP的服务启动脚本。
QNAP的QTS使用了一个修改过的Linux系统。看上去,系统启动时, /etc/init.d/rcS和rcS_normal会遍历/etc/rcS_init.d和rcS.d里各个服务的启动脚本。但由于这些目录都是QTS启动时mount而成,所以无法通过直接修改他们来影响服务启动行为。QNAP的官方文档只提供了一种添加自定义启动项的方式。其实通过查看该wiki页面的历史可以发现,QNAP还曾经支持通过修改qpkg定义的方法添加自定义启动脚本。复制如下:
This method consists of declaring a dummy QPKG which launches your script at startup.
- Log into your QNAP device using SSH or Telnet, for instance by using Putty
- Edit QPKG config file:
# vi /etc/config/qpkg.conf
- Declare a new dummy package by adding something like that in this file, but take care about the order. e.g. if you would like to start a service from a optware package, be sure optware is initialized before:
[autorun] Name = autorun Version = 0.1 Author = neomilium Date = 2013-05-06 Shell = /share/MD0_DATA/.qpkg/autorun/autorun.sh Install_Path = /share/MD0_DATA/.qpkg/autorun Enable = TRUEAs you can see, Shell is the interesting variable: at boot-time, QNAP OS will launch each QPKG’s Shell variable content.
Note: if your NAS doesn’t have /share/MD0_DATA (i.e. is a one-drive NAS), put the right directory into the Shell and Install_Path variables and adapt the following commands to your needs.
- Create the dummy package directory:
# mkdir /share/MD0_DATA/.qpkg/autorun
- Create the autorun script with the contents of your choice:
# vi /share/MD0_DATA/.qpkg/autorun/autorun.shNote: don’t forget “#!/bin/sh” at the beginning of script.
- Set the execute bit:
# chmod +x /share/MD0_DATA/.qpkg/autorun/autorun.sh
- Reboot and enjoy!
对于调整qpkg的启动顺序,就更简单了:只要修改相关qpkg在/etc/config/qpkg.conf里出现的先后顺序就可以了。我遇到的Gitea无法启动问题在交换了qpkg.conf中Gitea和QGit的qpkg信息模块位置后迎刃而解。
另外,还有一个QNAP第三方工具可以自定义qpkg的启动加载顺序,工具本身已经做成了一个qpkg,在QnapClub里就能安装,应该非常方便。开源项目地址:https://github.com/OneCDOnly/SortMyQPKGs