布署环境为debian 7.5node
布署到一台新机器,系统版本为debian 8.0linux
原启动项web
/etc/init.d/mongo_servicedocker
开机竟然没法自起shell
开机自启动不能用了,看页面输出就发觉不对劲,肯定是systemd,以前搭建部署coreos(也是用的systemd) docker kubernetes接触过,很亲切,只是迁移要费点时间。api
原来debian升级8.0后,改成用systemd管理启动项。spa
查资料知,兼容原启动管理,systemd 会自动生成 unit。日志
输入code
systemctl enable mongo_serviceblog
systemd 会根据原/etc/init.d/mongo_service的内容自动建立一个新的 service 内容以下
root@debian:~# systemctl cat mongo_service.service # /run/systemd/generator.late/mongo_service.service # Automatically generated by systemd-sysv-generator [Unit] SourcePath=/etc/init.d/mongo_service Description=LSB: An object/document-oriented database Before=runlevel2.target runlevel3.target runlevel4.target runlevel5.target shutdown.target After=network-online.target local-fs.target remote-fs.target nss-lookup.target Wants=network-online.target Conflicts=shutdown.target [Service] Type=forking Restart=no TimeoutSec=5min IgnoreSIGPIPE=no KillMode=process GuessMainPID=no RemainAfterExit=yes SysVStartPriority=1 ExecStart=/etc/init.d/mongo_service start ExecStop=/etc/init.d/mongo_service stop
reboot 启动 OK
试了试forever 的开机自起。
这东西曾经比较麻烦,写在rc里,执行不起来。
通常的解决办法是是写个shell执行 foreve 再把这个shell加为service 并设置开机启动。
到了systemd这里,很是简单。
只要设个service就行。
内容以下
# /etc/systemd/system/hellowordweb.service [Unit] Description=hello wrod web site After=mongo_service.service Wants=network-online.target Conflicts=shutdown.target [Service] Type=forking Restart=no TimeoutSec=5min ExecStart=/bin/forever start /root/hellowordweb/bin/cluster.js ExecStop=/bin/forever stop /root/hellowordweb/bin/cluster.js
如下是启动日志
root@debian:~# systemctl status hellowordweb.service
hellowordweb.service - xiaoyun audit web site Loaded: loaded (/etc/systemd/system/hellowordweb.service; enabled) Active: active (running) since Mon 2015-06-01 06:22:49 EDT; 1s ago Process: 1128 ExecStart=/bin/forever start /root/hellowordweb/bin/cluster.js (code=exited, status=0/SUCCESS) Main PID: 1133 (node) CGroup: /system.slice/hellowordweb.service ├─1133 /root/node-v0.12.4-linux-x64/bin/node /lib/node_modules/forever/bin/monitor /root/hellowordweb/bin/cluster.js ├─1134 test-xiaoyun-data-api: master ├─1135 test-xiaoyun-data-api: worker 1 └─1136 test-xiaoyun-data-api: worker 2