我正在运行 Python 脚本来获取数据并将其放入数据库中,这在 Ubuntu 20.04 headless 上可能需要一天甚至更长时间,如下所示:
stdbuf -o0 -e0 -i0 /path/v3_start_fetch.sh >> /path/logs/v3_cronlog_start_fetch__`date +\%Y\%m\%d\%H\%M\%S`___.log 2>&1 &
剧本:
. /path/env_project_auto/bin/activate
cd /path/working_scripts
python -u v3_updater_direct.py
每个异常也将被记录到 MySQL 数据库中。
问题:每次我运行任何脚本(我尝试了几个不同的脚本)时,它似乎都会在完全相同的时间停止,即 23:36。这是最后一个日志条目(每秒生成多个日志条目)。无论脚本是在 1 小时前还是 15 小时前运行,停止时间始终相同。
在系统日志中似乎有一些可疑的东西指向了这个问题,但我不明白它是什么,因为所有相关的条目Stopping User Manager for UUID xxx
似乎都与 NVidia 启动问题有关,比如这, 尽管这个问题沒有答案。
日志条目:
Oct 30 23:25:01 torbenserver02 CRON[12977]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Oct 30 23:26:01 torbenserver02 CRON[12986]: (torben) CMD (echo "`date +%Y%m%d%H%M%S`: `dig +short torben.ddns.net`" >> /home/torben/Projects/ip.log)
Oct 30 23:26:08 torbenserver02 systemd[1]: session-975.scope: Succeeded.
Oct 30 23:26:18 torbenserver02 systemd[1]: Stopping User Manager for UID 1000...
Oct 30 23:26:18 torbenserver02 systemd[11289]: Stopped target Main User Target.
Oct 30 23:26:18 torbenserver02 systemd[11289]: Stopped target Basic System.
Oct 30 23:26:18 torbenserver02 systemd[11289]: Stopped target Paths.
Oct 30 23:26:18 torbenserver02 systemd[11289]: Stopped target Sockets.
Oct 30 23:26:18 torbenserver02 systemd[11289]: Stopped target Timers.
Oct 30 23:26:18 torbenserver02 systemd[11289]: dbus.socket: Succeeded.
Oct 30 23:26:18 torbenserver02 systemd[11289]: Closed D-Bus User Message Bus Socket.
Oct 30 23:26:18 torbenserver02 systemd[11289]: dirmngr.socket: Succeeded.
Oct 30 23:26:18 torbenserver02 systemd[11289]: Closed GnuPG network certificate management daemon.
Oct 30 23:26:18 torbenserver02 systemd[11289]: gpg-agent-browser.socket: Succeeded.
Oct 30 23:26:18 torbenserver02 systemd[11289]: Closed GnuPG cryptographic agent and passphrase cache (access for web browsers).
Oct 30 23:26:18 torbenserver02 systemd[11289]: gpg-agent-extra.socket: Succeeded.
Oct 30 23:26:18 torbenserver02 systemd[11289]: Closed GnuPG cryptographic agent and passphrase cache (restricted).
Oct 30 23:26:18 torbenserver02 systemd[11289]: gpg-agent-ssh.socket: Succeeded.
Oct 30 23:26:18 torbenserver02 systemd[11289]: Closed GnuPG cryptographic agent (ssh-agent emulation).
Oct 30 23:26:18 torbenserver02 systemd[11289]: gpg-agent.socket: Succeeded.
Oct 30 23:26:18 torbenserver02 systemd[11289]: Closed GnuPG cryptographic agent and passphrase cache.
Oct 30 23:26:18 torbenserver02 systemd[11289]: pk-debconf-helper.socket: Succeeded.
Oct 30 23:26:18 torbenserver02 systemd[11289]: Closed debconf communication socket.
Oct 30 23:26:18 torbenserver02 systemd[11289]: snapd.session-agent.socket: Succeeded.
Oct 30 23:26:18 torbenserver02 systemd[11289]: Closed REST API socket for snapd user session agent.
Oct 30 23:26:18 torbenserver02 systemd[11289]: Reached target Shutdown.
Oct 30 23:26:18 torbenserver02 systemd[11289]: systemd-exit.service: Succeeded.
Oct 30 23:26:18 torbenserver02 systemd[11289]: Finished Exit the Session.
Oct 30 23:26:18 torbenserver02 systemd[11289]: Reached target Exit the Session.
Oct 30 23:26:18 torbenserver02 systemd[1]: [email protected]: Succeeded.
Oct 30 23:26:18 torbenserver02 systemd[1]: Stopped User Manager for UID 1000.
Oct 30 23:26:18 torbenserver02 systemd[1]: Stopping User Runtime Directory /run/user/1000...
Oct 30 23:26:18 torbenserver02 systemd[1]: run-user-1000.mount: Succeeded.
Oct 30 23:26:18 torbenserver02 systemd[1]: [email protected]: Succeeded.
Oct 30 23:26:18 torbenserver02 systemd[1]: Stopped User Runtime Directory /run/user/1000.
Oct 30 23:26:18 torbenserver02 systemd[1]: Removed slice User Slice of UID 1000.
Oct 30 23:27:01 torbenserver02 CRON[13038]: (torben) CMD (echo "`date +%Y%m%d%H%M%S`: `dig +short torben.ddns.net`" >> /home/torben/Projects/ip.log)
Oct 30 23:28:01 torbenserver02 CRON[13046]: (root) CMD ( test -x /etc/cron.daily/popularity-contest && /etc/cron.daily/popularity-contest --crond)
编辑数据库在本地运行,没有配置备份。在我关闭所有 SSH shell 后,这种情况似乎会发生在某个任意时间,通常大约 1-2 小时。这个周末我下午停止工作时,这种情况发生在一天中的不同时间。此外,当我直接在机器上通过终端运行作业时,这种情况似乎不会发生。所以我做了所描述的事情这里,并将尝试重现该错误以查看是否有帮助。
答案1
我通常使用GNU 屏幕当我希望我的会话在关闭 SSH 会话后仍保留在服务器上时。它应该让您的会话在服务器上保持活动状态,然后防止 systemd 将其杀死。
答案2
这样做loginctl enable-linger *username*
发现这里保持我的进程运行。