New startup service file

pull/1/head
Dct Mei 2020-03-25 21:40:40 +08:00
parent 87e11835d6
commit b1b6900629
No known key found for this signature in database
GPG Key ID: 50BF8B712DCAD7EA
3 changed files with 23 additions and 13 deletions

View File

@ -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
}

View File

@ -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

View File

@ -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