cat /home/upload.sh
/usr/bin/scp -P 22 /home/material.gz root@remote_ip:/home
date >> /var/log/upload.log
upload.service 的设置
cat /etc/systemd/system/upload.service
[Unit]
Description=upload files into my vps
Before=shutdown.target reboot.target
Requires=network-online.target
After=network.target
[Service]
ExecStart=/bin/true
ExecStop=/bin/bash /home/upload.sh
[Install]
WantedBy=multi-user.target
该脚本可以在关机前将文件上传到我的 vps。
奇怪的是上传服务的日志。
journal -u upload
Apr 23 12:54:50 localhost systemd[1]: Stopping upload files into my vps...
Apr 23 12:55:13 localhost systemd[1]: Stopped upload files into my vps.
Apr 23 12:55:19 localhost systemd[1]: Started upload files into my vps.
Apr 23 12:55:19 localhost systemd[1]: Starting upload files into my vps...
为什么不是如下命令?
Apr 23 12:54:50 localhost systemd[1]: Stopping upload files into my vps...
Apr 23 12:55:13 localhost systemd[1]: Stopped upload files into my vps.
Apr 23 12:55:19 localhost systemd[1]: Starting upload files into my vps...
Apr 23 12:55:19 localhost systemd[1]: Started upload files into my vps.
只有最后两行不同,为什么?
哪个导致这种日志信息?
按照 George Udosen 说的做:在服务文件中试试这个 [Unit] Requires=network-online.target After=network.target network-online.target。
这根本没有用。
lshw -C cpu
*-cpu
product: Intel(R) Xeon(R) CPU E3-1275 v5 @ 3.60GHz
vendor: Intel Corp.
vendor_id: GenuineIntel
physical id: 1
bus info: cpu@0
width: 64 bits
capabilities: fpu fpu_exception wp vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp x86-64 constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf cpuid_faulting pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch ida arat epb pln pts dtherm hwp hwp_noitfy hwp_act_window hwp_epp invpcid_single tpr_shadow vnmi flexpriority ept vpid fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm rdseed adx xsaveopt xsavec xgetbv1 xsaves
根据当前可用的信息,我假设您有一个多核或至少是多线程 CPU,并且调度和问题解耦允许乱序执行,从而导致日志输出中出现这种乱序异常。我会
numactl
用来启动你的脚本。这是一个例子:numactl --physcpubind=0 /path/to/your/script
或在这种特定情况下
numactl --physcpubind=0 /home/upload.sh
这将在分配给您的芯片组(索引 0)的第一个核心/cpu 上运行您的进程,如中所列。
/proc/cpuinfo
这将强制脚本最多同时运行一个线程,但这并不意味着整个进程将仅由一个线程组成线。如果编写程序是为了生成一个新线程,它会这样做,但它将在与进程的其余部分相同的核心/cpu/线程上执行。编辑:请注意,通过将处理限制为单个线程/核心/cpu,这可能会导致手头任务的处理速度变慢。
资料来源:
https://superuser.com/questions/692138/how-to-force-a-process-to-run-on-a-single-thread-only-with-numactl
man numactl
https://en.wikipedia.org/wiki/Out-of-order_execution
https://en.wikipedia.org/wiki/Multithreading_(computer_architecture)