ip
#139574
Replies: 1 comment
-
Hi @daxigua12 , thanks for participating! Unfortunately, we don’t currently have moderators for languages other than English. Until that changes, we need to ask that everyone use English here in the GitHub Community when posting. We’ll be locking any posts in languages other than English for now, including this one. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Select Topic Area
Question
Body
#!/bin/bash
获取当前主机名
hostname=$(hostname)
更新 /etc/hosts 文件
sudo sed -i "s/127.0.0.1 localhost/& $hostname/" /etc/hosts
显示 /etc/hosts 文件内容以验证更改
echo "/etc/hosts 文件内容如下:"
cat /etc/hosts
echo "主机名 $hostname 已添加到 /etc/hosts 文件中 127.0.0.1 localhost 后面"
创建并编辑 /etc/systemd/system/pyrun.service 文件
sudo tee /etc/systemd/system/pyrun.service > /dev/null <<EOL
[Unit]
Description=ipchange
After=network.target
Wants=network.target
[Service]
Type=forking
ExecStart=/usr/bin/python3 /home/ipchange/main.py
StandardOutput=append:/var/log/pyrun.log
StandardError=append:/var/log/pyrun_error.log
[Install]
WantedBy=multi-user.target
EOL
重新加载 systemd 服务配置
sudo systemctl daemon-reload
echo "systemd 服务配置已重新加载"
启用 pyrun 服务使其开机自启
sudo systemctl enable pyrun.service
echo "启用 pyrun 服务使其开机自启"
启动 pyrun 服务
sudo systemctl start pyrun.service
echo "pyrun.service 服务已创建并启动"
Beta Was this translation helpful? Give feedback.
All reactions