我有一个shell脚本作为服务启用,以启动多个shell脚本,例如
service started script -> script1, script2 ,script3
Run Code Online (Sandbox Code Playgroud)
script1应该在tmux窗口中打开一个程序,如果我通过手动启动脚本,它确实可以正常工作./script1.sh,但是当通过服务启动脚本启动时,它没有上述错误:
open terminal failed: not a terminal
Run Code Online (Sandbox Code Playgroud)
为什么会这样?
我logging.info()想去journald(systemd).
到目前为止,我只发现了读取journald(不是我想要的)的python模块或者像这样工作的模块: journal.send('Hello world')
我尝试将Debian上使用的SysVintit脚本(以及LinuxMint和Ubuntu&Co.等衍生产品发行版)转换为Fedora或ArchLinux(以及Bridge或Manjaro等衍生发行版)上使用的系统服务,但即使是systemd启动系统比以前更加高效和多功能,我不明白如何制作简单的东西,比如在命令行上使用"可选"参数,如ExecStart =或ExecRestart =!
以下是我对SysVinit所做的事情:
#!/bin/sh
### BEGIN INIT INFO
# Provides: myprog
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: myprog init script
# Descripton: this script manages myprog
### END INIT INFO
# exit if myprog isn't installed
[ -x "/opt/mystuff/myrpog" ] || exit 0
case "$1" in
start)
cd /opt/mystuff
./myprog -r
echo
;;
stop)
cd /opt/mystuff
./myprog -x
;;
restart)
cd /opt/mystuff
./myprog -x …Run Code Online (Sandbox Code Playgroud) 我有一个脚本我想同时运行2个程序,一个是交流程序,另一个是cpulimit,我想先在后台以"&"启动C程序,然后得到C程序的PID和将它交给cpulimit,它也将在后台以"&"运行.
我尝试在下面这样做,它只是启动第一个程序,永远不会启动cpulimit.
另外,我使用archd中的systemd作为root用户运行它作为启动脚本.
#!/bin/bash
/myprogram &
PID=$!
cpulimit -z -p $PID -l 75 &
exit 0
Run Code Online (Sandbox Code Playgroud) 我想生成长时间运行的子进程,这些进程在主进程重新启动/死亡时仍然存在.从终端运行时这很好用:
$ cat exectest.go
package main
import (
"log"
"os"
"os/exec"
"syscall"
"time"
)
func main() {
if len(os.Args) == 2 && os.Args[1] == "child" {
for {
time.Sleep(time.Second)
}
} else {
cmd := exec.Command(os.Args[0], "child")
cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
log.Printf("child exited: %v", cmd.Run())
}
}
$ go build
$ ./exectest
^Z
[1]+ Stopped ./exectest
$ bg
[1]+ ./exectest &
$ ps -ef | grep exectest | grep -v grep | grep -v vim
snowm 7914 5650 0 23:44 …Run Code Online (Sandbox Code Playgroud) 我工作的地方阻止了Docker的默认DNS(例如8.8.8.8),所以我想更改默认值.我已经能够这样做了
$ docker daemon --dns <mydnsaddress>
Run Code Online (Sandbox Code Playgroud)
但我想使用systemd drop-in来实现这一点,因为官方Docker文档推荐这种方式.我做了一个/etc/systemd/system/docker.service.d/dns.conf文件,并使用了这样的东西:
[Service]
DNS=<mydnsaddress>
Run Code Online (Sandbox Code Playgroud)
但我只是不知道变量名应该是什么.我该如何设置?更重要的是,是否有一个页面记录了可以在Docker的systemd drop-ins中使用的所有配置变量?
(顺便说一句,这是Ubuntu 15.10上的Docker 1.9,虽然我不怀疑任何错误)
我正在尝试编写自己的(简单的)systemd服务,它可以做一些简单的事情.(就像使用shell脚本将数字1到10写入文件一样).我的服务文件如下所示.
[Unit]
Description=NandaGopal
Documentation=https://google.com
After=multi-user.target
[Service]
Type=forking
RemainAfterExit=yes
ExecStart=/usr/bin/hello.sh &
[Install]
RequiredBy = multi-user.target
Run Code Online (Sandbox Code Playgroud)
这是我的shell脚本.
#!/usr/bin/env bash
source /etc/profile
a=0
while [ $a -lt 10 ]
do
echo $a >> /var/log//t.txt
a=`expr $a + 1`
done
Run Code Online (Sandbox Code Playgroud)
由于某种原因,服务没有出现,systemctl显示以下输出.
root@TARGET:~ >systemctl status -l hello
* hello.service - NandaGopal
Loaded: loaded (/usr/lib/systemd/system/hello.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: https://google.com
Run Code Online (Sandbox Code Playgroud)
一直想弄清楚过去2天出了什么问题.有人可以帮我吗?
问候,nandanator
有没有人有一个示例,或者链接到如何定义由d-bus激活的systemd .service的示例?
我的理解是,如果我在这里创建一个test.service文件:
/usr/share/dbus-1/services/test.service
Run Code Online (Sandbox Code Playgroud)
具有以下内容:
[D-BUS Service]
Name=org.me.test
Exec="/tmp/testamundo.sh"
Run Code Online (Sandbox Code Playgroud)
现在可以通过对systemd.Manager的d-bus调用来启动/停止服务吗?如果是这样,怎么样?
我在 Red Hat Enterprise Linux Server 7.9 (Maipo) 上有这个 systemd 服务
\n[Unit]\nDescription = EUM Server Service\nPartOf=eum.service\n# Start this unit after the app.service start\nAfter=eum.service\nAfter=eum-db.service\n\n[Service]\nType=forking\nUser=root\nWorkingDirectory=/prod/appdynamics/EUMServer/eum-processor/\nExecStart=/usr/bin/sleep 45 && /bin/bash bin/eum.sh start\nRemainAfterExit=true\nExecStop=/bin/bash bin/eum.sh stop\n\n[Install]\nWantedBy=multi-user.target\nRun Code Online (Sandbox Code Playgroud)\n失败是因为它尝试选择后面的所有内容/usr/bin/sleep作为该命令的参数。我只想执行/usr/bin/sleep 45并在成功时执行bin/eum.sh start。我怎样才能让它发挥作用?
\xe2\x97\x8f eum-server.service - EUM Server Service\n Loaded: loaded (/etc/systemd/system/eum-server.service; enabled; vendor preset: disabled)\n Active: failed (Result: exit-code) since Fri 2021-07-02 00:00:53 CEST; 9min ago\n Process: 13860 ExecStart=/usr/bin/sleep 45 && /bin/bash bin/eum.sh start (code=exited, status=1/FAILURE)\n\nJul 02 00:00:53 lmlift06mnp001 systemd[1]: …Run Code Online (Sandbox Code Playgroud)