布署环境为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. 6.react 基础 - 关于 react 开发 的原则

    1. 声明式开发 通过绑定元素 在数据变更时 对元素进行动态渲染 2. 可以与其他框架并存 不在React的绑定元素内, 可以使用其他框架 如 ( vue jQuery 等 ) 进行元素操作 3. 组 ...

  2. ASP.NET ZERO 学习 导航菜单

    定义PageNames和PermissionName PageNames : Web/App_Start/Navigation/PageNames.cs public const string Das ...

  3. 装饰器参数加log

    #有多个函数,需要计算他们的执行时间,加logimport timedef logger(flag): def show_time(f): #foo对象 def inner(*x,**y): star ...

  4. 三、VIP课程:并发编程专题->01-并发编程之Executor线程池详解

    01-并发编程之Executor线程池详解 线程:什么是线程&多线程 线程:线程是进程的一个实体,是 CPU 调度和分派的基本单位,它是比进程更小的能独立运行的基本单位.线程自己基本上不拥有系 ...

  5. 【图论算法】Dijstra&BFS

    选择V-S中的点加入S时用了贪心思想,即求d[]中legth最小且未被标记(未加入加入S)的点. 一点都没优化的实现: import java.lang.reflect.Array; /** * Cr ...

  6. 电影评论分类:二分类问题(IMDB数据集)

    IMDB数据集是Keras内部集成的,初次导入需要下载一下,之后就可以直接用了. IMDB数据集包含来自互联网的50000条严重两极分化的评论,该数据被分为用于训练的25000条评论和用于测试的250 ...

  7. Maven--优化依赖

    Maven 会自动解析所有项目的直接依赖和传递依赖,并且根据规则正确判断每个依赖的范围,对于一些依赖冲突,也能进行调节,以确保任何一个构件只有唯一的版本在依赖中存在.在这些工作之后,最后得到的那些依赖 ...

  8. ios avplayer 监控播放进度

      var timeObserver = avPlayerVC.player?.addPeriodicTimeObserver(forInterval: CMTime.init(value: , ti ...

  9. semantic框架 - selection dropdown自定义样式

    semantic和Bootstrap是我最常用的前端框架. 这次需求,是要修改selection dropdown. 直接贴代码,不解释. .ui.form input:not([type]):foc ...

  10. anaconda学习笔记

    anaconda介绍 Anaconda指的是一个开源的Python发行版本,其包含了conda.Python等180多个科学包及其依赖项. Conda是一个开源的包.环境管理器,可以用于在同一个机器上 ...