由于某些软件并没有增加开启启动的服务,很多时候需要手工添加,一般我们都是推荐添加命令到 /etc/rc.local 文件,但是 Debian 9 默认不带 /etc/rc.local 文件,而 rc.local 服务却还是自带的

root@debian9 ~ # cat /lib/systemd/system/rc.local.service

#  This file is part of systemd.

#

#  systemd is free software; you can redistribute it and/or modify it

#  under the terms of the GNU Lesser General Public License as published by

#  the Free Software Foundation; either version 2.1 of the License, or

#  (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by

# systemd-rc-local-generator if /etc/rc.local is executable.

[Unit]

Description=/etc/rc.local Compatibility

ConditionFileIsExecutable=/etc/rc.local

After=network.target

[Service]

Type=forking

ExecStart=/etc/rc.local start

TimeoutSec=0

RemainAfterExit=yes

GuessMainPID=no

并且默认情况下这个服务还是关闭的状态

root@debian9 ~ # systemctl status rc-local

● rc-local.service - /etc/rc.local Compatibility

Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)

Drop-In: /lib/systemd/system/rc-local.service.d

└─debian.conf

Active: inactive (dead)

为了解决这个问题,我们需要手工添加一个 /etc/rc.local 文件

cat <<EOF >/etc/rc.local

#!/bin/sh -e

#

# rc.local

#

# This script is executed at the end of each multiuser runlevel.

# Make sure that the script will "exit 0" on success or any other

# value on error.

#

# In order to enable or disable this script just change the execution

# bits.

#

# By default this script does nothing.

exit 0

EOF

然后赋予权限

chmod +x /etc/rc.local

接着启动 rc-local 服务

systemctl start rc-local

再次查看状态

root@debian9 ~ # systemctl status rc-local

● rc-local.service - /etc/rc.local Compatibility

Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)

Drop-In: /lib/systemd/system/rc-local.service.d

└─debian.conf

Active: active (exited) since Thu 2017-08-03 09:41:18 UTC; 14s ago

Process: 20901 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)

Aug 03 09:41:18 xtom-proxy systemd[1]: Starting /etc/rc.local Compatibility...

Aug 03 09:41:18 xtom-proxy systemd[1]: Started /etc/rc.local Compatibility.

然后你就可以把需要开机启动的命令添加到 /etc/rc.local 文件,丢在 exit 0 前面即可,并尝试重启以后试试是否生效了

转载自https://www.zhangweijie.net/post/2017/08/14/2868.html

----------------------------------- 后  记---------------------------------------------

当初我是为了将ankiserver部署到debian9 虚拟机上,并让它随着虚拟机启动而启动ankiserver服务而查的资料。

另外案例下另外一个收获:让你的vmware 随机启动,并让虚拟机也启动,关机时停止运行

https://www.cnblogs.com/chenxiaonian/p/6274965.html   注意,将vmware的目录设为环境变量

https://www.vmware.com/support/ws5/doc/ws_learning_cli_vmrun.html

搭建anki server时,我参考的https://zhuanlan.zhihu.com/p/25042942?refer=-anki  和 https://www.jianshu.com/p/c50e3feec878

最新文章

  1. codeforces B. Ohana Cleans Up
  2. C#获得类的方法和方法参数
  3. 查看数据库中没有进行comment的字段
  4. 多语言架构下如何正确的使用SQL视图
  5. OkHttp使用教程
  6. POJ 1155 (树形DP+背包+优化)
  7. Python的安装
  8. git总结
  9. 分享29个超赞的响应式Web设计
  10. JAVA实现AES和MD5加密
  11. 最长公共子序列--nyoj36
  12. unix c 05
  13. spring boot 入门操作(二)
  14. 大数据学习系列之五 ----- Hive整合HBase图文详解
  15. 2018年如何快速学Java
  16. Redis结合Lua脚本实现高并发原子性操作
  17. HTTP与HTTPS有哪些区别?
  18. linux 命令 — 文件相关
  19. PE 添加系统管理员账号(域控可加)转
  20. scoketserver模块(TCP协议 与 udp 协议)

热门文章

  1. JVM系列第12讲:JVM参数之查看JVM参数
  2. 强如 Disruptor 也发生内存溢出?
  3. SpringCloud(7)---网关概念、Zuul项目搭建
  4. centos7 修改yum源为阿里源
  5. PE知识复习之PE的导入表
  6. VS2015安装水晶报表
  7. 痞子衡嵌入式:并行接口NAND互操作性标准(JEDEC-JESD230)
  8. httpclient+jsoup实现小说线上采集阅读
  9. SpringCloud系列——Eureka 服务注册与发现
  10. Asp.net的DataGrid实现列冻结(C#)