systemd

How can I configure a systemd service to restart periodically?

青春壹個敷衍的年華 提交于 2019-12-02 15:30:12
I have a simple systemd service that needs to be periodically restarted to keep its process from bugging out. Is there a configuration option for systemd services to periodically restart them? All of the Restart* options seem to pertain to restarting the service when it exits. Yes, you can make your service to restart it periodically by making your service of Type=notify . Add this option in [Service] section of your service file along with Restart=always and give WatchdogSec=xx , where xx is the time period in second you want to restart your service. Here your process will be killed by

systemed(centos7)

五迷三道 提交于 2019-12-02 15:18:36
系统启动流程: POST→bootsequence→bootloader(MBR)→kernel→initramfs(initrd)→rootfs→/sbin/init init: centos5:Sys V init centos6:Upstart centos7:Systemd Systemd新特性: 系统引导时实现服务并行启动 按需激活进程 系统状态快照 基于依赖关系定义服务控制逻辑 核心概念unit: 通过配置文件进行标识和配置:文件中主要包含了系统服务(.service)、监听套接字(.socket)、保存的系统快照、以及其他与init相关的信息; 保存位置: /usr/lib/systemd/system/* /run/systemd/system/*:优先级高于上面 /etc/systemd/system/*:优先级高于上面 unit相当于centos6里/etc/init.d/目录中的脚本,不过unit没有执行权限,类似于配置文件; unit类型: service unit:扩展名为.service,用于定义系统服务; target unit:扩展名为.target,用于模拟centos6中的运行界别概念; device unit:扩展名为.device,用于用于定义内核识别的设备; mount unit:扩展名为mount,用于定义文件系统挂载点; socket

Linux之systemd服务配置及自动重启

China☆狼群 提交于 2019-12-02 15:00:08
0 背景 在linux上开发时,往往需要将自己的程序做成服务,并且实现服务开机自动重启,以及服务崩溃后自动重启功能,本文就对该功能的实现做简单介绍,实现方法很简单,使用linux系统的systemd即可实现 1 systemd介绍 历史上,linux的启动一直采用init进程,比如 $ sudo /etc/init.d/apache2 start # 或者 $ service apache2 start 这种方法有两个缺点。 一是启动时间长。 init 进程是串行启动,只有前一个进程启动完,才会启动下一个进程。 二是启动脚本复杂。 init 进程只是执行启动脚本,不管其他事情。脚本需要自己处理各种情况,这往往使得脚本变得很长。 Systemd 就是为了解决这些问题而诞生的。它的设计目标是,为系统的启动和管理提供一套完整的解决方案。根据 Linux 惯例,字母 d 是守护进程(daemon)的缩写。 Systemd 这个名字的含义,就是它要守护整个系统。使用了 Systemd,就不需要再用 init 了。Systemd 取代了 initd ,成为系统的第一个进程(PID 等于 1),其他进程都是它的子进程。 Systemd 并不是一个命令,而是一组命令,涉及到系统管理的方方面面。 systemctl 是 Systemd 的主命令,用于管理系统。对于用户来说,最常用的是下面这些命令

Linux:systemd配置jar启动服务

六月ゝ 毕业季﹏ 提交于 2019-12-02 14:29:45
systemctl管理服务启动、停止、开机启动 在/lib/systemd/system目录下创建一个脚本文件testjar.service vim /lib/systemd/system/testjar.service #表示基础信息 [ Unit ] #描述 Description = testjar Service #在哪个服务之后启动 After = syslog.target network.target remote-fs.target nss-lookup.target #表示服务信息 [ Service ] PIDFile = /var/run/testjar.pid User = workspace Group = workspace WorkingDirectory = /home/workspace/testjar ExecStart = /usr/local/java/jdk1.8.0_221/bin/java -jar /home/workspace/testjar/testjar.jar ExecReload = /bin/kill -s HUP $MAINPID ExecStop = /bin/kill -s QUIT $MAINPID PrivateTmp = true #安装相关信息 [ Install ] WantedBy = multi

Raspberry Pi - Autostart OpenCv-Script - Error with cv::imshow()

好久不见. 提交于 2019-12-02 11:51:54
Short Description: I want to auto-start an executable (opencv binary file, generate via c++) via a systemd service-script after booting, but I am unsuccessful. I narrowed down the error to the code statement "cv::imshow(....)" which opens a window and displays an image. At this point, the code throws the error: "QXcbConnection: Could not connect to display" However, if I manually execute the sh-script or the binary, both work fine. I searched around stackoverflow for the most common errors, and I tried to fix all I could found. I am quite sure, that: My service file actually runs at start

CentOS7下MySQL服务启动失败原因及解决方法

只谈情不闲聊 提交于 2019-12-02 11:19:48
在重启阿里的CentOS7服务器后,重启MySQL 出现错误 Starting mysqld (via systemctl): Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details. [FAILED] 按照提示查看错误信息 [root@djaljdw ~]# systemctl status mysqld.service ● mysqld.service - SYSV: MySQL database server. Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled) Active: failed (Result: exit-code) since Thu 2019-08-22 14:42:39 CST; 1min 25s ago Docs: man:systemd-sysv-generator(8) Process: 2427 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status

How to get actual path to executable when using .netcore 3.0 and using the /p:PublishSingleFile=true flag?

China☆狼群 提交于 2019-12-02 11:19:23
问题 I recently upgraded an application to dotnet core 3 and started using the PublishSingleFile flag during the build process. With these two changes the way the executable path is found has changed. Now instead of getting the path where the executable file is, I get redirected to a random directory in /var/tmp/.net/ where as I used to get /opt/appdir/ . Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)); Edit: So it seems like the random dir it is spitting

Linux使用systemd管理私有服务,实现故障重启、开机自启动等功能

纵饮孤独 提交于 2019-12-02 10:40:34
Linux使用systemd管理私有服务,实现故障重启、开机自启动等功能 Systemd 是 Linux 系统中新一代的初始化系统(init),它主要的设计目标是克服 sysvinit 固有的缺点,提高系统的启动速度。很多新的Linux发行版已经使用Systemd取代了init,作为初始守护进程。 Swoole的服务器程序可以编写一段service脚本,交由systemd进行管理。实现故障重启、开机自启动等功能。 编写Service脚本 Systemd 的 Service 配置在 /etc/systemd/system/ 目录中,可以创建一个 echo.service 文件,实际项目应当改为对应的名称。编辑此文件,添加下列内容: [ Unit ] Description = Echo Http Server After = network.target After = syslog.target [ Service ] Type = simple LimitNOFILE = 65535 ExecStart = /usr/bin/php /opt/servers/echo/server.php ExecReload = /bin/kill -USR1 $MAINPID Restart = always [ Install ] WantedBy = multi-user.target

一、安装linux系统

一个人想着一个人 提交于 2019-12-02 09:53:32
一、安装linux系统 1、点击新建 2、注意: linux与windows的 鼠标切换: 键盘右侧的ctrl(必须是右侧的); 1)选择语言 2) 3)开启网络 4)点击开始安装 5)用户设置 6)登入 7) 给linux配置ip 进行远程管理 如果网络不同的话需要配置网卡,命令如下: vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 回车 就出现网络的环境 如果最后一项onboot是no的话 需要进行修改为yes 此时可以完成网卡的配置修改BooTPROTO="dhcp"的值 修改为static 可以实现为系统设置静态ip的功能 在它下面增加命令 IPADDR=192.168.1.111(随机写) NETMASK=255.255.255.0 GATEWAY=“192.168.1.1” NM_CONTROLLED=no 之后按esc退出 输入:w(保存) :q(退出) 再输入命令重启网络服务 systemctl restart network.service 验证ip是否设置成功 输入ip addr 在其中就可以看到设置的静态ip了 8) 防火墙运行远程登陆这台电脑 防火墙运行的端口是22需要开启22端口 ssh 输入以下命令 firewall-cmd --zone=public--add-port=22/tcp --permanent

2.Ansible Playbook剧本

夙愿已清 提交于 2019-12-02 09:40:46
1.playbook?playbook翻译过来就是“剧本”,那playbook组成如下 play: 定义的是主机的角色 task: 定义的是具体执行的任务 playbook: 由一个或多个play组成,一个play可以包含多个task任务 简单理解为: 使用不同的模块完成一件事情 通俗理解playbook? - playbook 剧本 <---文件 YAML - play 找谁 明星 找那个主机 web01 - task 做什么 干什么事情 yum copy service - 找多个明星,做多件事情 - 找一个明星,做多件事情 2.playbook的优势 1.功能比ad-hoc更全 2.能很好的控制先后执行顺序, 以及依赖关系 3.语法展现更加的直观 4.ad-hoc无法持久使用,playbook可以持久使用 3.playbook的配置语法是由yaml语法描述的,扩展名是yaml 缩进 YAML使用固定的缩进风格表示层级结构,每个缩进由两个空格组成, 不能使用tabs 冒号 以冒号结尾的除外,其他所有冒号后面所有必须有空格。 短横线 表示列表项,使用一个短横杠加一个空格。 多个项使用同样的缩进级别作为同一列表 Playbook执行结果返回颜色状态: 红色: 表示有task执行失败或者提醒的信息 黄色:表示执行了且改变了远程主机状态 绿色:表示执行成功 4