这里有人能够启动/停止/重新加载/...使用通配符或 systemctl 上的类似方法指定的单位列表吗?
我尝试做类似的事情:systemctl restart openstack-nova-*.services或systemctl restart openstack-nova-?.services
但这是一个死胡同,我在 systemctl 的手册上没有找到任何有用的东西。
我可以使用 for 循环,但在此之前我必须systemctl -t service --failed为列出的单位制作一个然后 grep ......有点无聊不是吗?
所以,如果有人知道是否可以做这样的事情,我会很高兴听到的。
如果不是,我想我会在 systemctl 开发人员列表上提出这个想法,或者如果我有时间的话可能会打补丁 ^^
通过 systemctl 运行 haproxy 与手动运行它不同。
这是通过 systemctl 启动时的输出:
> sudo systemctl status -l haproxy.service
haproxy.service - HAProxy Load Balancer
Loaded: loaded (/usr/lib/systemd/system/haproxy.service; enabled)
Active: active (running) since Wed 2014-12-24 08:08:49 EST; 4min 59s ago
Main PID: 20307 (haproxy)
CGroup: /system.slice/haproxy.service
??20307 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
Dec 24 08:08:49 localhost.localdomain systemd[1]: Starting HAProxy Load Balancer...
Dec 24 08:08:49 localhost.localdomain systemd[1]: Started HAProxy Load Balancer.
Run Code Online (Sandbox Code Playgroud)
像这样,haproxy 只对我的后端说 503。
如果我现在停止 haproxy 服务,而是在命令行上手动运行它,如下所示:
sudo /usr/sbin/haproxy …Run Code Online (Sandbox Code Playgroud) 好吧,我有一个配置了systemctl的服务。这是配置文件:
[Unit]
Description=The description of the service (:
After=network.target
[Service]
ExecStartPre=/bin/echo 'Starting Service' >> /var/log/node/myapp.log
ExecStart=/root/.nvm/versions/node/v5.0.0/bin/node ./bin/www
ExecStopPost=/bin/echo 'Stopping Service' >> /var/log/node/myapp.log
Restart=always
#StandardOutput=/var/log/node/myapp.log
#StandardError=/var/log/node/myapp.log
SyslogIdentifier=myapp
Environment=NODE_ENV=production
WorkingDirectory=/home/user/node-apps/theapp
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
我需要的?:
1)ExecStartPre和ExecStopPost可以写入消息'starting service'或写入'stopping service'文件/var/log/node/myapp.log。用上面的配置,不起作用,它只输出'Starting Service' >> /var/log/node/myapp.logand 'Stopping Service' >> /var/log/node/myapp.logto journalctl。(我检查过journalctl -u myapp)
2)我需要的是,而不是应用程序的所有日志,输出到journalctl, 可以输出到文件。例如:/var/log/node/myapp.log。我的意思是,如果在我的应用程序中,我有一个console.log(),这可能在那里。
使用upstart,我可以这样做:
script
exec start-stop-daemon --start --make-pidfile --pidfile /var/run/upstart-yourapp.pid …Run Code Online (Sandbox Code Playgroud) 我有一个systemd.socket名为gunicorn.socket,我想在远程服务器上更新一些代码后重新启动。
我已按照允许非 root 用户重新启动服务中详述的步骤操作并systemctl不断询问我的用户密码。这是我尝试systemctl restart gunicorn.socket与 user一起运行时所做的john:
# added an appadmin group to allow the restart command to john
addgroup appadmin
usermod -a -G appadmin john
visudo
Run Code Online (Sandbox Code Playgroud)
在sudoers:
Cmnd_Alias MYAPP_CMNDS = /bin/systemctl start gunicorn.socket, /bin/systemctl stop gunicorn.socket, /bin/systemctl restart gunicorn.socket
%appadmin ALL=(ALL) NOPASSWD: MYAPP_CMNDS
Run Code Online (Sandbox Code Playgroud)
然后sudo systemctl restart gunicorn.socket在服务器上工作正常,但是当我远程尝试时,我得到:
ssh example.com "sudo systemctl restart gunicorn.socket"
Failed to restart gunicorn.socket: Interactive authentication required.
See …Run Code Online (Sandbox Code Playgroud) 像这样杀死正在运行的守护进程 systemd 服务有什么区别:
kill -SIGKILL 3645
和
systemctl -s kill -SIGKILL 3645
其中 3645 是 systemd 服务的 pid。使用第一种方法有什么缺点吗?
我首先在 StackOverflow 上问了这个问题,但似乎这个网站更合适。
我正在设置一个 Web 应用程序环境来运行 Java 应用程序。环境应该是:
我启动了 EC2 实例并安装了 java,然后按照本指南设置 Tomcat: https: //www.digitalocean.com/community/tutorials/install-tomcat-9-ubuntu-1804
systemctl现在,当尝试启动/重新启动 Tomcat 服务时,问题就会出现。这是我在检查 systemctl 日志时看到的内容:
12 月 19 日 13:35:25 ip-10-165-10-74 systemd[1]: tomcat.service: 服务延迟时间结束,计划重新启动。 12 月 19 日 13:35:25 ip-10-165-10-74 systemd[1]: tomcat.service: 计划重启作业,重启计数器为 5。 12 月 19 日 13:35:25 ip-10-165-10-74 systemd[1]:已停止 Apache Tomcat Web 应用程序容器。 12 月 19 日 13:35:25 ip-10-165-10-74 systemd[1]:启动 Apache Tomcat Web 应用程序容器... 12 月 19 日 13:35:25 ip-10-165-10-74startup.sh[1705]:Tomcat 已启动。 12 月 19 日 13:35:25 …
我有一个在 nginx 后面运行 gunicorn/Django 的开发服务器。作为更广泛的服务器环境更新的一部分,我尝试将 gunicorn 从 18.0 升级到 19.2.1,但该服务将不再启动。(服务器正在运行 Arch,因此使用 systemctl。)
gunicorn 配置是由不再受我们支配的人完成的,并且对 gunicorn 不是很了解,我无法修复甚至定位问题,所以我恢复到 18.0 版并且它现在可以工作。但是,我想最终升级它并使配置处于可以工作的状态。我有一种感觉,当前的配置是次优或多余的,但我无法确定:-)。
环境(或运行gunicorn的virtualenv)没有任何变化,只有gunicorn本身升级了。Systemctl 在systemctl start gunicorn以下位置产生此错误:
? gunicorn.service - gunicorn daemon (production)
Loaded: loaded (/usr/lib/systemd/system/gunicorn.service; enabled)
Active: failed (Result: resources) since Tue 2015-02-17 20:55:41 UTC; 8s ago
Process: 2837 ExecStop=/bin/kill -s QUIT $MAINPID (code=exited, status=0/SUCCESS)
Process: 9608 ExecReload=/bin/kill -s HUP $MAINPID (code=exited, status=0/SUCCESS)
Process: 5353 ExecStart=/home/django/gunicorn/run.sh (code=exited, status=0/SUCCESS)
Main PID: 24876 (code=exited, status=0/SUCCESS)
Feb 17 20:55:41 ashima systemd[1]: PID file /home/django/gunicorn/gunicorn.pid not …Run Code Online (Sandbox Code Playgroud) 我正在运行来自 apt.postgresql.org 的 Debian Stretch 和 PostgreSQL 10。当我做:
postgresql disable --now postgresql
Run Code Online (Sandbox Code Playgroud)
数据库服务器不会停止。它说:
Synchronizing state of postgresql.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable postgresql
insserv: warning: current start runlevel(s) (empty) of script `postgresql' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script `postgresql' overrides LSB defaults (0 1 6).
Run Code Online (Sandbox Code Playgroud)
但这可能并不重要。
systemctl disable --now postgresql@10-main做这份工作,但我对postgresql单位很好奇。它的start, stop,任务restart工作reload正常。 …
当我同时使用多个服务运行 systemctl status 时,例如
sudo systemctl status myservice1 myservice2 myservice3 我看到了输出,但最后我看到了
lines 1-48/48 (END)
或者如果输出更大,参数更多
lines 1-62
我可以滚动或分页输出并使用 q 退出。
是否可以更改此行为以立即打印所有日志输出并退出命令?
我正在阅读有关的联机帮助页systemctl reload,发现这句话是关于reload.
reload PATTERN...
Asks all units listed on the command line to reload their
configuration.
Run Code Online (Sandbox Code Playgroud)
http://man7.org/linux/man-pages/man1/systemctl.1.html
systemd 是如何做到的?systemd 使用什么 API 来要求单元重新加载其配置?
我也发现了reload-or-restart。
reload-or-restart PATTERN...
Reload one or more units if they support it. If not, restart them
instead.
Run Code Online (Sandbox Code Playgroud)
systemd 如何知道单元是否支持重新加载?
systemctl ×10
systemd ×5
gunicorn ×2
arch-linux ×1
centos ×1
haproxy ×1
journalctl ×1
journald ×1
kill ×1
kill-process ×1
linux ×1
logging ×1
postgresql ×1
recursive ×1
socket ×1
sudo ×1
tomcat ×1
ubuntu ×1