systemd systemctl

0.systemd概念

可以看下面几篇:
https://www.ibm.com/developerworks/cn/linux/1407_liuming_init3/
http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.html
https://jingyan.baidu.com/article/cbcede07193a9102f40b4d3a.html

几乎所有systemctl 相关的命令的例子(很赞的排版):
https://linux.cn/article-5926-1.html


1.常用的命令:

sudo systemctl list-units --type=service # 只显示开启状态的service?
sudo systemctl list-unit-files --type=service # 会显示各种状态的service?
sudo systemctl start foo.service 
sudo systemctl stop foo.service 
sudo systemctl restart foo.service 
sudo systemctl enable foo.service
sudo systemctl disable foo.service
sudo systemctl daemon-reload #更改配置文件之后,会提示需要执行此命令

更多systemctl 请参考这篇


2.相关文件

环境 ubuntu 16.04LTS
配置文件存在的方式有两类:
一类是和原先的rc0-6那套差不多,
/etc/init.d 中有可执行脚本,负责service的start stop
另一类是标准的systemctl的service文件,
/lib/systemd/system 中,以service作为后缀
一个service文件的例子:

[Unit]
Description=shadowsocks server

[Service]
Type=simple
ExecStart=/usr/local/bin/ssserver -c /etc/shadowsocks/config.json

[Install]
WantedBy=multi-user.target

另一个例子:ssh.service

[Unit]
Description=OpenBSD Secure Shell server
After=network.target auditd.service
ConditionPathExists=!/etc/ssh/sshd_not_to_be_run

[Service]
EnvironmentFile=-/etc/default/ssh
ExecStart=/usr/sbin/sshd -D $SSHD_OPTS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartPreventExitStatus=255
Type=notify

[Install]
WantedBy=multi-user.target
Alias=sshd.service
~

这两种方式配置的服务,都可以使用1中提到的start stop restart


3.关于配置文件中的@

参考这篇
这篇
尝试失败

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值