首先是这样做的:
systemctl stop mosquitto
update-rc.d mosquitto remove
rm /etc/init.d/mosquitto
Run Code Online (Sandbox Code Playgroud)
单元文件如下:
[Unit]
Description=MQTT v3.1 message broker
After=network.target
Requires=network.target
[Service]
Type=simple
ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
Restart=always
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
的结果:
sudo systemctl status mosquitto -l
Run Code Online (Sandbox Code Playgroud)
是:
? mosquitto.service - MQTT v3.1 message broker
Loaded: loaded (/etc/systemd/system/mosquitto.service; enabled)
Active: failed (Result: start-limit) since Sun 2017-01-01 19:44:03 GMT; 3min 23s ago
Process: 683 ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf (code=exited, status=1/FAILURE)
Main PID: 683 (code=exited, status=1/FAILURE)
Jan 01 19:44:03 raspberrypi systemd[1]: Unit mosquitto.service entered failed state.
Jan 01 19:44:03 …Run Code Online (Sandbox Code Playgroud) 在 Debian 上升级 Postgresql 版本后,我注意到旧版本的 postgres 继续出现。
$ systemctl | grep postgresql
postgresql@oldversion-main.service loaded failed failed PostgreSQL Cluster oldversion-main
postgresql@newversion-main.service loaded active running PostgreSQL Cluster newversion-main
Run Code Online (Sandbox Code Playgroud)
如何删除“旧版本”?
附注。我已经使用删除了“旧版本”apt-get remove
谢谢
service apache2 reload和 和有sudo systemctl restart apache2什么区别?
我知道有人使用 sudo 而其他人则没有。另外,我可以理解重新加载和重新启动之间的区别。但是这两个命令之间的主要区别是什么?
我写了简单的systemd服务文件goserver.service:
[Unit]
Description=Goserver
[Service]
ExecStart=/usr/bin/go run /home/denis/goserver/index.go
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
但是当我尝试运行服务并获取状态时:
$ sudo systemctl status goserver.service
Run Code Online (Sandbox Code Playgroud)
我收到错误:
??? 02 12:28:04 DV go[13627]: home/denis/goserver/index.go:6:2: cannot find package "gopkg.in/mgo.v2" in any of:
??? 02 12:28:04 DV go[13627]: /usr/lib/go-1.6/src/gopkg.in/mgo.v2 (from $GOROOT)
??? 02 12:28:04 DV go[13627]: ($GOPATH not set)
Run Code Online (Sandbox Code Playgroud)
但是$GOPATH使用export命令设置:
$ export GOPATH="/home/denis/goserver/"
$ ls $GOPATH
goserver.log index.go pkg src templates
Run Code Online (Sandbox Code Playgroud)
命令行中的这个命令工作正常:
$ /usr/bin/go run /home/denis/goserver/index.go
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用systemd服务它不起作用.
如何在检测到的情况下运行systemd服务$GOPATH?(没有命令创建的二进制文件go build...)
我的 app.service 文件的 [Service] 部分如下:-
[Service]
Type=forking
Restart=no
IgnoreSIGPIPE=no
GuessMainPID=no
ExecStart=/opt/app/appl_init.d start
ExecStop=/opt/app/appl_init.d stop
TimeoutSec=infinity
Run Code Online (Sandbox Code Playgroud)
之后我安装了该应用程序,并将文件正确复制到/usr/lib/systemd/system/app.service.
我跑了systemctl daemon-reload,但是好像对启动时间没有影响!它在我运行时失败systemctl start app或systemctl reload app.service出现以下错误:-
Job for app.service failed because a fatal signal was delivered to the control process. See "systemctl status app.service" and "journalctl -xe" for details
Run Code Online (Sandbox Code Playgroud)
输出systemctl status app为:-
? app.service - ApplicationTest
Loaded: loaded (/opt/app/appl_init.d; enabled; vendor preset: disabled)
Active: failed (Result: signal) since Tue 2017-03-21 01:55:22 EDT; 1min 4s …Run Code Online (Sandbox Code Playgroud) 似乎在上面找不到任何东西,我也是一个奇怪的人。
我有一个非常频繁地插入数据库记录的 python 程序,它仍在这样做,所以我知道该程序仍在运行。
我将程序设置为 systemctl 中的服务单元,并记录到 journalctl。
几个月来日志一直很好,但今天 1 点钟停止将日志添加到该单元的日志数据中。
这只是内存问题吗?我不知道为什么,但我认为 journalctl 会处理这个问题。
在 ec2 实例上的 Amazon Linux 2 上,我编辑了弹性代理服务,但收到错误“参数数量无效”
[ec2-user@ip-172-31-21-92 ~]$ sudo systemctl daemon-reload elastic-agent
Invalid number of arguments.
Run Code Online (Sandbox Code Playgroud)
我已编辑我的服务文件,如下所示:
[Unit]
Description=Agent manages other beats based on configuration provided.
Documentation=https://www.elastic.co/products/beats/elastic-agent
Wants=network-online.target
After=network-online.target
[Service]
Environment="BEAT_LOG_OPTS="
Environment="BEAT_CONFIG_OPTS=-c /etc/elastic-agent/elastic-agent.yml"
Environment="BEAT_PATH_OPTS=--path.home /usr/share/elastic-agent --path.config /etc/elastic-agent --path.data /var/lib/elastic-agent --path.logs /var/log/elastic-agent"
ExecStart=/usr/share/elastic-agent/bin/elastic-agent --environment systemd $BEAT_LOG_OPTS $BEAT_CONFIG_OPTS $BEAT_PATH_OPTS -v
Restart=always
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
我对已安装文件所做的唯一编辑是将“-v”标志添加到 ExecStart 的末尾
我有以下服务文件:
[Unit]
Description=MyApp
After=syslog.target network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
WorkingDirectory=/opt/nodejs-sites/MyApp
ExecStart=/usr/bin/npm start
Environment=NODE_ENV=development
User=root
Group=root
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=MyApp
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
这是来自 /var/log/syslog 的错误
Oct 14 13:00:55 devu18 systemd[1]: Started myapp.
Oct 14 13:00:55 devu18 systemd[3203]: myapp.service: Changing to the requested working directory failed: No such file or directory
Oct 14 13:00:55 devu18 systemd[3203]: myapp.service: Failed at step CHDIR spawning /usr/bin/npm: No such file or directory
Oct 14 13:00:55 devu18 systemd[1]: myapp.service: Main process exited, code=exited, status=200/CHDIR
Oct 14 13:00:55 …Run Code Online (Sandbox Code Playgroud) 我对服务的自动运行有疑问。我想在用户登录后运行脚本。一旦我成功了,但是当我尝试使其自动化时,就会遇到错误,并且找不到错误。
服务:
Description=Service desc
[Service]
Type=oneshot
Environment=DISPLAY=:0.0
Environment=XAUTHORITY=/home/albert/.Xauthority
Environment=HOME=/home/albert/
User=albert
Group=albert
RemainAfterExit=true
StandardOutput=journal
ExecStart=/home/albert/.startup-script.sh
[Install]
WantedBy=default.target
Run Code Online (Sandbox Code Playgroud)
位置:/home/albert/.config/systemd/user/startup-service.service
权限:-rw-r--r-- 1 albert albert 306 Jan 2 14:49 startup-service.service
脚本
权限:-rwxr-xrx 1 albert albert 86 Jan 2 13:30 /home/albert/.startup-script.sh
日志记录
Jan 02 17:03:27 irpi-epsilon systemd[734]: Service desc
-- Subject: Unit UNIT has begun start-up
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- Unit UNIT has begun starting up.
Jan 02 17:03:27 irpi-epsilon systemd[1025]: startup-script.service: Failed at step GROUP spawning /home/albert/.startup-script.sh: Operation not permitted …Run Code Online (Sandbox Code Playgroud) 我已经更新了webmin,但是现在,它拒绝重新启动:
? webmin.service - LSB: web-based administration interface for Unix systems
Loaded: loaded (/etc/init.d/webmin; generated; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2018-07-29 09:30:29 CEST; 12s ago
Docs: man:systemd-sysv-generator(8)
Process: 1485 ExecStart=/etc/init.d/webmin start (code=exited, status=2)
Jul 29 09:30:26 vps513135 systemd[1]: Starting LSB: web-based administration interface for Unix systems...
Jul 29 09:30:27 vps513135 perl[1486]: pam_unix(webmin:auth): authentication failure; logname= uid=0 euid=0 tty= ruser= rhost= user=root
Jul 29 09:30:29 vps513135 systemd[1]: webmin.service: Control process exited, code=exited status=2
Jul 29 09:30:29 vps513135 …Run Code Online (Sandbox Code Playgroud) 首先,感谢您对此问题的调查!
我是 bash 脚本的新手,我想要实现的是:我目前必须经常在工作中重新启动一些服务,我正在尝试创建一个脚本来自动化它,我设法创建了所有内容,但我也想创建一个条件,其中如果 systemctl status = inactive 则 echo“好的,很好,一切都很好”,所以让我们继续,但如果没有,则 echo“将在 10 秒内重新尝试重新启动”;我使用 grep 从服务的 systemctl 状态中查找文本“active: active (running)”或“active: inactive (dead)”(由下面的 bluetooth.service 表示):
#!/bin/bash
#Restarting bluetooth.service
clear
active_stop="Active: stopped (dead)"
echo "This script will RESTART the following service: Bluetooth.Service"
echo -e "State the REASON for the RESTART: " >> /home/sjadmin/SYS_RESTART/ARCHIVE/sysrestart.log
read -p "Press ENTER to continue or CTRL + C to cancel"
sudo systemctl stop bluetooth.service |grep active IF [[grep -q=$active_stop]]
then read -p "Service STOPPED, please confirm status bellow, …Run Code Online (Sandbox Code Playgroud) 我最近转移到 fedora 34 并尝试安装 MS Sql Server,但它无法启动。安装是干净的,设置是通过运行完成的
sudo /opt/mssql/bin/mssql-conf setup
Run Code Online (Sandbox Code Playgroud)
状态检查
sudo systemctl status mssql-server
Run Code Online (Sandbox Code Playgroud)
返回这个
mssql-server.service - Microsoft SQL Server Database Engine
Loaded: loaded (/usr/lib/systemd/system/mssql-server.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Mon 2021-08-30 18:51:56 EEST; 11min ago
Docs: https://learn.microsoft.com/en-us/sql/linux
Process: 1027 ExecStart=/opt/mssql/bin/sqlservr (code=exited, status=127)
Run Code Online (Sandbox Code Playgroud)
日志说:
8 月 30 日 18:51:55 fedora systemd[1]:启动 Microsoft SQL Server 数据库引擎。 8 月 30 日 18:51:55 fedora sqlservr[933]:/opt/mssql/bin/sqlservr:加载共享库时出错:libldap-2.4.so.2:无法打开共享对象文件:没有这样的文件或 > 8月30日18:51:55 fedora systemd [1]:mssql-server.service:主进程退出,代码=退出,状态= 127/n/a 8月30日18:51:55 fedora systemd [1]:mssql-server .service:失败,结果为“退出代码”。 …
我所有的 UNIX 主机都使用 LDAP 后端。
\n\ndocker组已存在于 ldap 上,这也是为什么docker.service必须在nslcd.service.
我尝试编辑systemctl启动配置docker.service:
$ sudo systemctl edit --full docker.service\nRun Code Online (Sandbox Code Playgroud)\n\n我添加nslcd.service到After,,Wants:Requires
[Unit]\nDescription=Docker Application Container Engine\nDocumentation=https://docs.docker.com\nAfter=network-online.target docker.socket firewalld.service nslcd.service\nWants=network-online.target nslcd.service\nRequires=docker.socket nslcd.service\nRun Code Online (Sandbox Code Playgroud)\n\n我仍然无法让 docker 在该服务之后运行:
\n\nsudo service docker status\n\xe2\x97\x8f docker.service - Docker Application Container Engine\n Loaded: loaded (/etc/systemd/system/docker.service; enabled; vendor preset: enabled)\n Active: inactive (dead)\n Docs: https://docs.docker.com\n\nOct 10 19:35:02 dev-08 systemd[1]: Dependency failed for …Run Code Online (Sandbox Code Playgroud)