布署环境为debian 7.5

布署到一台新机器,系统版本为debian 8.0

原启动项

/etc/init.d/mongo_service

开机居然无法自起

开机自启动不能用了,看页面输出就发觉不对劲,确定是systemd,之前搭建部署coreos(也是用的systemd) docker kubernetes接触过,很亲切,只是迁移要费点时间。

原来debian升级8.0后,改为用systemd管理启动项。

查资料知,兼容原启动管理,systemd 会自动生成 unit。

输入

systemctl enable mongo_service

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

linux debain systemd 开机启动 nodejs 兼容原initd启动 forever 开机自启的更多相关文章

  1. 走进Linux之systemd启动过程

    Linux系统的启动方式有点复杂,而且总是有需要优化的地方.传统的Linux系统启动过程主要由著名的init进程(也被称为SysV init启动系统)处理,而基于init的启动系统被认为有效率不足的问 ...

  2. linux 启动过程以及如何将进程加入开机自启

    linux 启动流程 系统启动主要顺序就是: 1. 加载内核 2. 启动初始化进程 3. 确定运行级别 4. 加载开机启动程序 5. 用户登录 启动流程的具体细节可以看看Linux 的启动流程 第4步 ...

  3. Linux基础知识之挂载详解(mount,umount及开机自动挂载)

    Linux基础知识之挂载详解(mount,umount及开机自动挂载) 转载自:http://www.linuxidc.com/Linux/2016-08/134666.htm 挂载概念简述: 根文件 ...

  4. Linux 服务器 U盘安装(避免U盘启动)以及拔除U盘后无法引导系统

    一.U盘制作 首先下载两个文件: ·         rhel-server-6.3-i386-boot.iso    启动镜像 ·         rhel-server-6.3-i386-dvd. ...

  5. Linux之systemd服务配置及自动重启

    layout: post title: Linux之systemd服务配置及自动重启 date: 2019-09-09 tags: linux --- Linux之systemd服务配置及自动重启 0 ...

  6. 【Linux】- Systemd 命令篇

    转自:阮一峰的网络日志 Systemd 是 Linux 系统工具,用来启动守护进程,已成为大多数发行版的标准配置. 一.由来 历史上,Linux 的启动一直采用init进程. 下面的命令用来启动服务. ...

  7. .NET Worker Service 部署到 Linux 作为 Systemd Service 运行

    上一篇文章我们了解了如何将.NET Worker Service 作为 Windows 服务运行,今天我接着介绍一下如何将 Worker Service 部署到 Linux 上,并作为 Systemd ...

  8. Linux 使用 Systemd 管理进程服务

    转载自:https://mp.weixin.qq.com/s/e-_PUNolUm22-Uy_ZjpuEA systemd 介绍 systemd是目前Linux系统上主要的系统守护进程管理工具,由于i ...

  9. Linux服务器,服务管理--systemctl命令详解,设置开机自启动

    Linux服务器,服务管理--systemctl命令详解,设置开机自启动 syetemclt就是service和chkconfig这两个命令的整合,在CentOS 7就开始被使用了. 摘要: syst ...

随机推荐

  1. rename 修改文件名

    Linux的 rename 命令有两个版本,一个是C语言版本的,一个是Perl语言版本的,早期的Linux发行版基本上使用的是C语言版本的,现在已经很难见到C语言版本的了,由于历史原因,在Perl语言 ...

  2. java android环境变量配置

    JAVA_HOME   用于jdk配置D:\Program Files\Java\jdk1.8.0_25 path %JAVA_HOME%\bin;;%JAVA_HOME%\jre\bin;;D:\P ...

  3. shift+alt 可对notepadplusplus 打开的文档进行列操作

    shift+alt 可对notepadplusplus 打开的文档进行列操作

  4. tensorflow函数解析:Session.run和Tensor.eval

    原问题链接: http://stackoverflow.com/questions/33610685/in-tensorflow-what-is-the-difference-between-sess ...

  5. 吴裕雄--天生自然 PHP开发学习:多维数组

    <pre> <?php // 二维数组: $cars = array ( array("Volvo",100,96), array("BMW" ...

  6. JIT Debug Info 简介

    原总结debug调试dump转储文件JITprocdumpJIT Debugging 前言 在上一篇介绍 JIT Debugging 的文章 -- 你需要了解的JIT Debugging 中,我们了解 ...

  7. 理论优美的深度信念网络--Hinton北大最新演讲

    什么是深度信念网络 深度信念网络是第一批成功应用深度架构训练的非卷积模型之一. 在引入深度信念网络之前,研究社区通常认为深度模型太难优化,还不如使用易于优化的浅层ML模型.2006年,Hinton等研 ...

  8. 正则表达式中 /s 可以帮助“.”匹配所有的字符,包括换行,从而实现【\d\D】的功能

    正则表达式中 /s 可以帮助“.”匹配所有的字符,包括换行,从而实现[\d\D]的功能

  9. TOJ-2811 Bessie's Weight Problem(DP、背包问题)

    链接:https://ac.nowcoder.com/acm/contest/1082/K 题目描述 Bessie, like so many of her sisters, has put on a ...

  10. 没有更好的,五种操作系统助力研发,IMX6开发板做得到

    核心板参数 尺寸 51mm*61mm 四核商业级-2G NXP 四核 i.MX6Q,主频 1 GHz 内存:2GB DDR3:存储:16GB EMMC:SATA接口:支持 双核商业级-1G NXP 双 ...