From b1b6900629346848138ad1eb773416b31ee6fac2 Mon Sep 17 00:00:00 2001 From: Dct Mei Date: Wed, 25 Mar 2020 21:40:40 +0800 Subject: [PATCH] New startup service file --- install-release.sh | 4 +++- systemd/system/v2ray.service | 18 ++++++------------ systemd/system/v2ray@.service | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 systemd/system/v2ray@.service diff --git a/install-release.sh b/install-release.sh index d73a075..0bc96d8 100644 --- a/install-release.sh +++ b/install-release.sh @@ -341,18 +341,20 @@ installV2Ray(){ # Used to store V2Ray log files if [[ ! -d '/var/log/v2ray/' ]]; then - install -d /var/log/v2ray/ + install -d -o nobody -g nobody /var/log/v2ray/ fi } installStartupServiceFile() { if [[ ! -f '/etc/systemd/system/v2ray.service' ]]; then mkdir "${TMP_DIRECTORY}systemd/system/" curl ${PROXY} -o "${TMP_DIRECTORY}systemd/system/v2ray.service" https://raw.githubusercontent.workers.dev/v2fly/fhs-install-v2ray/master/systemd/system/v2ray.service -s + curl ${PROXY} -o "${TMP_DIRECTORY}systemd/system/v2ray@.service" https://raw.githubusercontent.workers.dev/v2fly/fhs-install-v2ray/master/systemd/system/v2ray@.service -s if [[ "$?" -ne '0' ]]; then echo 'error: Failed to start service file download! Please check your network or try again.' exit 1 fi install -m 755 "${TMP_DIRECTORY}systemd/system/v2ray.service" /etc/systemd/system/v2ray.service + install -m 755 "${TMP_DIRECTORY}systemd/system/v2ray@.service" /etc/systemd/system/v2ray@.service fi } diff --git a/systemd/system/v2ray.service b/systemd/system/v2ray.service index 976be53..5500066 100644 --- a/systemd/system/v2ray.service +++ b/systemd/system/v2ray.service @@ -1,20 +1,14 @@ [Unit] Description=V2Ray Service -After=network.target -Wants=network.target +After=network-online.target +Wants=network-online.target [Service] -# This service runs as root. You may consider to run it as another user for security concerns. -# By uncommenting the following two lines, this service will run as user v2ray/v2ray. -# More discussion at https://github.com/v2ray/v2ray-core/issues/1011 -# User=v2ray -# Group=v2ray Type=simple -PIDFile=/run/v2ray.pid -ExecStart=/usr/bin/env V2RAY_LOCATION_ASSET=/usr/local/lib/v2ray /usr/local/bin/v2ray -config /usr/local/etc/v2ray/config.json -Restart=on-failure -# Don't restart in the case of configuration error -RestartPreventExitStatus=23 +User=nobody +AmbientCapabilities=CAP_NET_BIND_SERVICE +Environment=V2RAY_LOCATION_ASSET=/usr/local/lib/v2ray/ +ExecStart=/usr/local/bin/v2ray -confdir /usr/local/etc/v2ray/ [Install] WantedBy=multi-user.target diff --git a/systemd/system/v2ray@.service b/systemd/system/v2ray@.service new file mode 100644 index 0000000..5f9d2b6 --- /dev/null +++ b/systemd/system/v2ray@.service @@ -0,0 +1,14 @@ +[Unit] +Description=V2Ray Service +After=network-online.target +Wants=network-online.target + +[Service] +Type=simple +User=nobody +AmbientCapabilities=CAP_NET_BIND_SERVICE +Environment=V2RAY_LOCATION_ASSET=/usr/local/lib/v2ray/ +ExecStart=/usr/local/bin/v2ray -config /usr/local/etc/v2ray/%i.json + +[Install] +WantedBy=multi-user.target