Alpine Linux 实现开机自启脚本
前面我们安装了Alpine,具体参考这个:Linux下OpenVZ平台Alpine Linux一键安装脚本 ,然后想着继续搞下去,因为这小东西长得太精致了,就研究了下开机自启的办法,具体方法如下:
Alpine Linux 的 开机自启目录在/etc/local.d下,这个目录用于放置我们需要在本地服务启动或停止后执行的脚本。
先上目录下的说明文档:
This directory should contain programs or scripts which are to be run
when the local service is started or stopped.
If a file in this directory is executable and it has a .start extension,
it will be run when the local service is started. If a file is
executable and it has a .stop extension, it will be run when the local
service is stopped.
All files are processed in lexical order.
Keep in mind that files in this directory are processed sequentially,
and the local service is not considered started or stopped until
everything is processed, so if you have a process which takes a long
time to run, it can delay your boot or shutdown processing.
when the local service is started or stopped.
If a file in this directory is executable and it has a .start extension,
it will be run when the local service is started. If a file is
executable and it has a .stop extension, it will be run when the local
service is stopped.
All files are processed in lexical order.
Keep in mind that files in this directory are processed sequentially,
and the local service is not considered started or stopped until
everything is processed, so if you have a process which takes a long
time to run, it can delay your boot or shutdown processing.
简单翻译了下:
此目录应包含在启动或停止本地服务时要运行的程序或脚本。如果此目录中的文件是可执行文件且扩展名为.start,则在启动本地服务时将运行该文件。如果文件是可执行的并且具有.stop扩展名,则在本地服务停止时将运行该文件。所有文件都按词汇顺序处理。请记住,此目录中的文件是按顺序处理的,并且在处理完所有内容之前不会将本地服务视为已启动或停止,因此如果您的进程需要很长时间才能运行,则可能会延迟启动或关闭处理。
我们现在需要开机自启ss服务,由于Alpine Linux自带了nohup后台守护,我们就直接使用nohup设置开机自启。
先编辑下ss.start文件,注意,.start后缀需要固定,前面名称随意:
vi ss.start //编辑文件
nohup python3 /usr/local/shadowsocks/server.py -c /root/1.json & //填充数据
nohup python3 /usr/local/shadowsocks/server.py -c /root/1.json & //填充数据
然后保存退出。
赋予脚本可执行权限:
chmod +x ss.start
设置 local 服务开机启动:
rc-update add local
这样当系统开机时就能执行ss.start开达到开机自动的目的。
继续阅读