diff --git a/scripts/install_systemd.sh b/scripts/install_systemd.sh index 04b99e9..b581131 100755 --- a/scripts/install_systemd.sh +++ b/scripts/install_systemd.sh @@ -10,47 +10,63 @@ Service_User="root" Service_Group="root" Unit_Path="/etc/systemd/system/${Service_Name}.service" -PID_FILE="$Server_Dir/temp/clash.pid" +Env_File="$Server_Dir/temp/clash-for-linux.sh" #################### 权限检查 #################### if [ "$(id -u)" -ne 0 ]; then - echo -e "\033[31m[ERROR] 需要 root 权限来安装 systemd 单元\033[0m" + echo -e "[ERROR] 需要 root 权限来安装 systemd 单元" exit 1 fi #################### 目录初始化 #################### -install -d -m 0755 \ - "$Server_Dir/conf" \ - "$Server_Dir/logs" \ - "$Server_Dir/temp" +install -d -m 0755 "$Server_Dir/conf" "$Server_Dir/logs" "$Server_Dir/temp" + +# 预创建 env 文件,避免 systemd 因路径不存在报错 +: > "$Env_File" +chmod 0644 "$Env_File" #################### 生成 systemd Unit #################### -cat >"$Unit_Path"<"$Unit_Path" </dev/null 2>&1 || true -echo -e "\033[32m[OK] 已生成 systemd 单元: ${Unit_Path}\033[0m" -echo -e "可执行以下命令启动服务:" -echo -e " sudo systemctl enable --now ${Service_Name}.service" +echo -e "[OK] 已生成 systemd 单元: ${Unit_Path}" +echo -e "已启用开机自启,可执行以下命令启动服务:" +echo -e " systemctl restart ${Service_Name}.service" +echo -e "查看状态:" +echo -e " systemctl status ${Service_Name}.service -l --no-pager"