diff --git a/release/config/systemd/v2ray.service b/release/config/systemd/v2ray.service new file mode 100644 index 000000000..b988be090 --- /dev/null +++ b/release/config/systemd/v2ray.service @@ -0,0 +1,13 @@ +[Unit] +Description=V2Ray Service +After=network.target +Wants=network.target + +[Service] +Type=forking +PIDFile=/var/run/v2ray.pid +ExecStart=start-stop-daemon --start --quiet --pidfile /var/run/v2ray.pid --exec /usr/bin/v2ray/v2ray --background -m -- -config /etc/v2ray/config.json +ExecStop=start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile /var/run/v2ray.pid + +[Install] +WantedBy=multi-user.target diff --git a/release/install-release.sh b/release/install-release.sh index eae55fbd0..9e3bfb0e3 100755 --- a/release/install-release.sh +++ b/release/install-release.sh @@ -46,8 +46,14 @@ if [ ! -f "/etc/v2ray/config.json" ]; then echo "UUID:${UUID}" fi -# Configure SysV if necessary. -if [ -d "/etc/init.d" ]; then +#if [ -d "/lib/systemd/system" ]; then +# if [ ! -f "/lib/systemd/system/v2ray.service" ]; then +# cp "/tmp/v2ray/v2ray-${VER}-linux-${VDIS}/systemd/v2ray.service" "/lib/systemd/system/" +# systemctl enable v2ray +# fi +#el + +if [ -d "/etc/init.d" ]; then # Configure SysV if necessary. if [ ! -f "/etc/init.d/v2ray" ]; then cp "/tmp/v2ray/v2ray-${VER}-linux-${VDIS}/systemv/v2ray" "/etc/init.d/v2ray" chmod +x "/etc/init.d/v2ray" diff --git a/tools/build/config.go b/tools/build/config.go index f59a6603b..2b7856e31 100644 --- a/tools/build/config.go +++ b/tools/build/config.go @@ -55,6 +55,15 @@ func copyConfigFiles(dir string, goOS GoOS) error { if err := copyConfigFile(src, dest, goOS, false); err != nil { return err } + + if err := os.MkdirAll(filepath.Join(dir, "systemd"), os.ModeDir|0777); err != nil { + return err + } + src = filepath.Join(srcDir, "systemd", "v2ray.service") + dest = filepath.Join(dir, "systemd", "v2ray.service") + if err := copyConfigFile(src, dest, goOS, false); err != nil { + return err + } } return nil