布署环境为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. OpenMP笔记(三)

    个人博客地址:http://www.bearoom.xyz/2019/02/21/openmp3/ 这一部分主要记录一些指令的使用. 一.parallel的使用 parallel是用于构造并行块的,也 ...

  2. MySql、Mongodb和Redis的区别

    NoSQL 的全称是 Not Only SQL,也可以理解非关系型的数据库,是一种新型的革命式的数据库设计方式,不过它不是为了取代传统的关系型数据库而被设计的,它们分别代表了不同的数据库设计思路. M ...

  3. 移植zlib

    平台说明 开发平台:Ubuntu12.04 编 译器:arm-linux-gcc version 4.4.4 (4.4.4_09.06.2010) Zlib源码包:zlib-1.2.11.tar.gz ...

  4. 87.QuerySet API使用详解:create方法

    create:创建一条数据,并且保存到数据库中,这个方法相当于先用指定的模型创建一个一个对象,然后再调用这个对象的save方法,示例代码如下: from django.db import connec ...

  5. redis在linux中的安装启动

    1. 拖到 /usr/local 下 2. 解压 tar zxf redis-4.0.8.tar.gz 3. mkdir /usr/redis 4. 编译     cd redis-4.0.8/src ...

  6. 打水滴(BFS)

    在一个n行m列的网格中,某些位置存在一些水滴.嘟嘟进行q次打水滴操作,每次嘟嘟在某一个网格当中添加一个水滴,当某一网格中的水滴数量超过L时,该网格中的水滴变为四个水滴,并分别向上下左右四个方向飞出,每 ...

  7. windows支持apache、mysql、php集成环境推荐wampserver3.2 64位版本

    对英文不感冒的同学很容易下载到更新包,而且官方的下载速度很慢,此文件为官方原版下载,现在分享给大家. 链接:https://pan.baidu.com/s/1LYyJi6FddvkQQNrLp4L6W ...

  8. swift bannerview 广告轮播图

    class BannerView: UIView,UIScrollViewDelegate{ //图⽚⽔平放置到scrollView上 private var scrollView:UIScrollV ...

  9. 判断1/N是否为无限小数

    给定一个正整数N,请判断1/N是否为无限小数,若是输出YES,若不是请输出NO. 思路: 只要被除数n可以转换成2的次幂或者2与5的组合即为有限小数,否则为无线小数 代码如下: #include &l ...

  10. 吴裕雄--天生自然 pythonTensorFlow自然语言处理:Seq2Seq模型--测试

    import sys import codecs import tensorflow as tf # 1.参数设置. # 读取checkpoint的路径.9000表示是训练程序在第9000步保存的ch ...