linux知识问答

£可爱£侵袭症+ 提交于 2020-01-13 04:57:43

目录

 

1. systemd是什么?

2.如何利用systemd, 让自己写的程序运行出错后,可以自动重启

   1)在/lib/systemd/system, 下面创建文件,gogs.service

 2)


1. systemd是什么?

  参考:http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.html

   systemd相对于传统的init, 是操作系统启动的首个进程,然后启动systemd管理的各个服务,d指的是daemon, 守护进程

每个服务,存放在/lib/systemd/system/, 下面,sytemctl enable后,会在/etc/systemd/system/下面创建一个软链接指向这个服务

2.如何利用systemd, 让自己写的程序运行出错后,可以自动重启

   1)在/lib/systemd/system, 下面创建文件,gogs.service

   

[Unit]
Description=Gogs
After=network.target
 
[Service]
# Modify these two values and uncomment them if you have
# repos with lots of files and get an HTTP error 500 because
# of that
###
#LimitMEMLOCK=infinity
#LimitNOFILE=65535
Type=forking
User=gogs
Group=gogs
WorkingDirectory=/usr/local/git/gogs
ExecStart=/bin/sh /usr/local/git/gogs/gogs.sh
Restart=always
Environment=USER=gogs HOME=/home/gogs
 
# Some distributions may not support these hardening directives. If you cannot start the service due
# to an unknown option, comment out the ones not supported by your version of systemd.
#ProtectSystem=full
#PrivateDevices=yes
#PrivateTmp=yes
#NoNewPrivileges=true
 
[Install]
WantedBy=multi-user.target

————————————————
版权声明:本文为CSDN博主「码农农码一生」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/chenhao_c_h/article/details/92064209

 2)操作service

systemctl daemon-reload
systemctl enable gogs.service
systemctl start gogs.service
  查看 sercvice 状态
systemctl status gogs.service

  

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!