您尚未登录。

#1 2022-10-04 20:56:06

kuzuda
会员
注册时间: 2022-10-04
帖子: 2

用Systemd服务实现自动更新系统

Question:
1.我想使用Systemd Service来执行一个自动更新系统(Pacman)的脚本 日志显示在选择Y/n时会报错
2.我想让它安全执行完(比如执行完成才退出)
谢谢您的帮助:0

log:
Oct 03 22:11:38 archlinux bash[3160]: Updating System Don't poweroff
Oct 03 22:11:38 archlinux sudo[3162]:     root : PWD=/ ; USER=root ; COMMAND=/usr/bin/pacman -Syyu
Oct 03 22:11:38 archlinux sudo[3162]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=0)
Oct 03 22:11:38 archlinux bash[3163]: :: Synchronizing package databases...
Oct 03 22:11:40 archlinux bash[3163]:  core downloading...
Oct 03 22:11:40 archlinux bash[3163]:  extra downloading...
Oct 03 22:11:40 archlinux bash[3163]:  community downloading...
Oct 03 22:11:40 archlinux bash[3163]:  multilib downloading...
Oct 03 22:11:40 archlinux bash[3163]: :: Starting full system upgrade...
Oct 03 22:11:41 archlinux bash[3163]: resolving dependencies...
Oct 03 22:11:41 archlinux bash[3163]: looking for conflicting packages...
Oct 03 22:11:41 archlinux bash[3163]: Packages (1) v2ray-domain-list-community-20221003054842-1
Oct 03 22:11:41 archlinux bash[3163]: Total Download Size:   0.14 MiB
Oct 03 22:11:41 archlinux bash[3163]: Total Installed Size:  1.36 MiB
Oct 03 22:11:41 archlinux bash[3163]: Net Upgrade Size:      0.00 MiB
Oct 03 22:11:41 archlinux sudo[3162]: pam_unix(sudo:session): session closed for user root
Oct 03 22:11:41 archlinux bash[3163]: :: Proceed with installation? [Y/n]
Oct 03 22:11:41 archlinux systemd[1]: update.service: Main process exited, code=exited, status=1/FAILURE
Oct 03 22:11:41 archlinux systemd[1]: update.service: Failed with result 'exit-code'.

update.service:
[Unit]
Description=update

[Service]
ExecStart=bash /update.sh

[Install]
WantedBy=multi-user.target


update.sh:
#!/bin/bash

echo "Updating System Don't poweroff"
sudo pacman -Syyu

离线

#2 2022-10-05 00:14:18

依云
会员
所在地: a.k.a. 百合仙子
注册时间: 2011-08-21
帖子: 8,430
个人网站

Re: 用Systemd服务实现自动更新系统

建议了解一下 pacroller
不是换镜像的话,不要用 -yy。白下载数据浪费网络流量。
加 --noconfirm 参数可以让 pacman 不询问。
建议使用 systemd-inhibit 禁止关机啥的,免得更新到一半被中断了。

离线

#3 2022-10-05 13:30:38

kuzuda
会员
注册时间: 2022-10-04
帖子: 2

Re: 用Systemd服务实现自动更新系统

谢谢 感谢你的帮助 现在它确实达到我的目标
万分感谢

离线

页脚