布署环境为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. Log4Net 使用及组合公共类

    好记性不如烂笔头,这次是由衷的感受到了! log4net 是一个很好用的日志记录工具,引用入项目中,如何查看项目内部运行情况,如何快速定位异常信息,好的日志记录能帮很大的忙: log4net 很好用, ...

  2. 基础练习--huffman

    问题描述 Huffman树在编码中有着广泛的应用.在这里,我们只关心Huffman树的构造过程. 给出一列数{pi}={p0, p1, …, pn-},用这列数构造Huffman树的过程如下: . 找 ...

  3. JavaScript 闭包究竟是什么JavaScript 闭包究竟是什么

    用JavaScript一年多了,闭包总是让人二丈和尚摸不着头脑.陆陆续续接触了一些闭包的知识,也犯过几次因为不理解闭包导致的错误,一年多了资料也看了一些,但还是不是非常明白,最近偶然看了一下 jQue ...

  4. RAC,ReactiveSwift

    1.创建信号 // 1.通过信号发生器创建(冷信号) let producer = SignalProducer<String, NoError>.init { (observer, _) ...

  5. c#之初识结构(Struct)

    C# 结构(Struct) 首先结构是值类型数据结构.它使得一个单一变量可以存储各种数据类型的相关数据.struct 关键字用于创建结构.通俗说:结构就是一个可以包含不同数据类型的集合.它是一种可以自 ...

  6. 安装 texlive

    多系统使用texlive 中文latex 用xelatex 编译 只需要加入宏包 \usepackage[UTF8]{ctex} Rmarkdown 配置模版 $ cat _output.yaml b ...

  7. 关于tomcat报错记录

    启动报错关键信息如下: Caused by: java.lang.IllegalStateException: Unable to complete the scan for annotations ...

  8. 14 微服务电商【黑马乐优商城】:day02-springcloud(理论篇二:知道什么是SpringCloud)

    本项目的笔记和资料的Download,请点击这一句话自行获取. day01-springboot(理论篇) :day01-springboot(实践篇) day02-springcloud(理论篇一: ...

  9. 如何将本地未提交的更改合并到另一个Git分支?

    如何在Git中执行以下操作? 我当前的分支是branch1,我做了一些本地更改. 但是,我现在意识到我实际上是要将这些更改应用于branch2. 有没有办法应用/合并这些更改,以便它们成为branch ...

  10. python学习——函数及其参数

    函数 函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段.函数能提高应用的模块性,和代码的重复利用率.严格来说python只有函数,没有过程,人们理解的函数都是带有return的,而过程 ...