Browse Source

Provides separated service files for RPM packages

As discussed with @librehat in #1604, maintaining a separate set of systemd
files for RPM distributions will be convenient to build on Copr.

This patch will also change some lines in rpm/genrpm.sh to archive the
source code using `git archive` because the old logic doesn't respect
`.gitignore`.
pull/1644/head
Yuxiang Zhu 7 years ago
committed by Max Lv
parent
commit
feeaff85e1
11 changed files with 212 additions and 62 deletions
  1. 10
      .gitignore
  2. 36
      rpm/SOURCES/0001-systemd-services.patch
  3. 27
      rpm/SOURCES/systemd/shadowsocks-libev-local.service
  4. 27
      rpm/SOURCES/systemd/shadowsocks-libev-local@.service
  5. 27
      rpm/SOURCES/systemd/shadowsocks-libev-redir@.service
  6. 27
      rpm/SOURCES/systemd/shadowsocks-libev-server@.service
  7. 27
      rpm/SOURCES/systemd/shadowsocks-libev-tunnel@.service
  8. 25
      rpm/SOURCES/systemd/shadowsocks-libev.default
  9. 27
      rpm/SOURCES/systemd/shadowsocks-libev.service
  10. 10
      rpm/SPECS/shadowsocks-libev.spec.in
  11. 31
      rpm/genrpm.sh

10
.gitignore

@ -44,11 +44,12 @@ shadowsocks-libev.pc
debian/libshadowsocks-libev*.symbols debian/libshadowsocks-libev*.symbols
libsodium/src/libsodium/include/sodium/version.h libsodium/src/libsodium/include/sodium/version.h
rpm/SPECS/shadowsocks-libev.spec rpm/SPECS/shadowsocks-libev.spec
rpm/SRPMS
rpm/SRPMS/
rpm/RPMS/ rpm/RPMS/
rpm/SOURCES/
!rpm/SOURCES/etc/init.d/shadowsocks-libev
rpm/BUILD
rpm/BUILD/
rpm/BUILDROOT/
*.rpm
*.deb
# Ignore per-project vim config # Ignore per-project vim config
.vimrc .vimrc
@ -87,6 +88,7 @@ doc/*.html
*.so *.so
*.pcf.gz *.pcf.gz
*.pdb *.pdb
*.tar
*.tar.bz2 *.tar.bz2
*.tar.gz *.tar.gz
*.tgz *.tgz

36
rpm/SOURCES/0001-systemd-services.patch

@ -1,36 +0,0 @@
diff -ru shadowsocks-libev-orig/debian/shadowsocks-libev.default shadowsocks-libev/debian/shadowsocks-libev.default
--- shadowsocks-libev-orig/debian/shadowsocks-libev.default 2017-06-02 08:45:07.000000000 +0800
+++ shadowsocks-libev/debian/shadowsocks-libev.default 2017-06-28 16:39:37.236474413 +0800
@@ -19,7 +19,7 @@
# User and group to run the server as
USER=nobody
-GROUP=nogroup
+GROUP=nobody
# Number of maximum file descriptors
MAXFD=32768
diff -ru shadowsocks-libev-orig/debian/shadowsocks-libev.service shadowsocks-libev/debian/shadowsocks-libev.service
--- shadowsocks-libev-orig/debian/shadowsocks-libev.service 2017-06-02 08:45:07.000000000 +0800
+++ shadowsocks-libev/debian/shadowsocks-libev.service 2017-06-28 17:23:55.131822730 +0800
@@ -6,7 +6,7 @@
# (at your option) any later version.
#
# This file is default for Debian packaging. See also
-# /etc/default/shadowsocks-libev for environment variables.
+# /etc/sysconfig/shadowsocks-libev for environment variables.
[Unit]
Description=Shadowsocks-libev Default Server Service
@@ -15,9 +15,9 @@
[Service]
Type=simple
-EnvironmentFile=/etc/default/shadowsocks-libev
+EnvironmentFile=/etc/sysconfig/shadowsocks-libev
User=nobody
-Group=nogroup
+Group=nobody
LimitNOFILE=32768
ExecStart=/usr/bin/ss-server -c $CONFFILE $DAEMON_ARGS

27
rpm/SOURCES/systemd/shadowsocks-libev-local.service

@ -0,0 +1,27 @@
# This file is part of shadowsocks-libev.
#
# Shadowsocks-libev is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This file is default for RPM packaging. See also
# /etc/sysconfig/shadowsocks-libev for environment variables.
[Unit]
Description=Shadowsocks-libev Default Local Service
Documentation=man:shadowsocks-libev(8)
After=network.target
[Service]
Type=simple
EnvironmentFile=/etc/sysconfig/shadowsocks-libev
User=nobody
Group=nobody
LimitNOFILE=32768
ExecStart=/usr/bin/ss-local -c "$CONFFILE" $DAEMON_ARGS
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target

27
rpm/SOURCES/systemd/shadowsocks-libev-local@.service

@ -0,0 +1,27 @@
# This file is part of shadowsocks-libev.
#
# Shadowsocks-libev is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This is a template unit file. Users may copy and rename the file into
# config directories to make new service instances. See systemd.unit(5)
# for details.
[Unit]
Description=Shadowsocks-Libev Custom Client Service for %I
Documentation=man:ss-local(1)
After=network.target
[Service]
Type=simple
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
ExecStart=/usr/bin/ss-local -c /etc/shadowsocks-libev/%i.json
User=nobody
Group=nobody
LimitNOFILE=32768
[Install]
WantedBy=multi-user.target

27
rpm/SOURCES/systemd/shadowsocks-libev-redir@.service

@ -0,0 +1,27 @@
# This file is part of shadowsocks-libev.
#
# Shadowsocks-libev is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This is a template unit file. Users may copy and rename the file into
# config directories to make new service instances. See systemd.unit(5)
# for details.
[Unit]
Description=Shadowsocks-Libev Custom Client Service Redir Mode for %I
Documentation=man:ss-redir(1)
After=network.target
[Service]
Type=simple
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
ExecStart=/usr/bin/ss-redir -c /etc/shadowsocks-libev/%i.json
User=nobody
Group=nobody
LimitNOFILE=32768
[Install]
WantedBy=multi-user.target

27
rpm/SOURCES/systemd/shadowsocks-libev-server@.service

@ -0,0 +1,27 @@
# This file is part of shadowsocks-libev.
#
# Shadowsocks-libev is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This is a template unit file. Users may copy and rename the file into
# config directories to make new service instances. See systemd.unit(5)
# for details.
[Unit]
Description=Shadowsocks-Libev Custom Server Service for %I
Documentation=man:ss-server(1)
After=network.target
[Service]
Type=simple
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
ExecStart=/usr/bin/ss-server -c /etc/shadowsocks-libev/%i.json
User=nobody
Group=nobody
LimitNOFILE=32768
[Install]
WantedBy=multi-user.target

27
rpm/SOURCES/systemd/shadowsocks-libev-tunnel@.service

@ -0,0 +1,27 @@
# This file is part of shadowsocks-libev.
#
# Shadowsocks-libev is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This is a template unit file. Users may copy and rename the file into
# config directories to make new service instances. See systemd.unit(5)
# for details.
[Unit]
Description=Shadowsocks-Libev Custom Client Service Tunnel Mode for %I
Documentation=man:ss-tunnel(1)
After=network.target
[Service]
Type=simple
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
ExecStart=/usr/bin/ss-tunnel -c /etc/shadowsocks-libev/%i.json
User=nobody
Group=nobody
LimitNOFILE=32768
[Install]
WantedBy=multi-user.target

25
rpm/SOURCES/systemd/shadowsocks-libev.default

@ -0,0 +1,25 @@
# Defaults for shadowsocks initscript
# sourced by /etc/init.d/shadowsocks-libev
# installed at /etc/default/shadowsocks-libev by the maintainer scripts
#
# This is a POSIX shell fragment
#
# Note: `START', `GROUP' and `MAXFD' options are not recognized by systemd.
# Please change those settings in the corresponding systemd unit file.
# Enable during startup?
START=yes
# Configuration file
CONFFILE="/etc/shadowsocks-libev/config.json"
# Extra command line arguments
DAEMON_ARGS="-u"
# User and group to run the server as
USER=nobody
GROUP=nobody
# Number of maximum file descriptors
MAXFD=32768

27
rpm/SOURCES/systemd/shadowsocks-libev.service

@ -0,0 +1,27 @@
# This file is part of shadowsocks-libev.
#
# Shadowsocks-libev is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This file is default for RPM packaging. See also
# /etc/sysconfig/shadowsocks-libev for environment variables.
[Unit]
Description=Shadowsocks-libev Default Server Service
Documentation=man:shadowsocks-libev(8)
After=network.target
[Service]
Type=simple
EnvironmentFile=/etc/sysconfig/shadowsocks-libev
User=nobody
Group=nobody
LimitNOFILE=32768
ExecStart=/usr/bin/ss-server -c "$CONFFILE" $DAEMON_ARGS
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target

10
rpm/SPECS/shadowsocks-libev.spec.in

@ -7,7 +7,6 @@ Group: Applications/Internet
License: GPLv3+ License: GPLv3+
URL: https://github.com/shadowsocks/%{name} URL: https://github.com/shadowsocks/%{name}
Source0: %{url}/archive/v%{version}.tar.gz Source0: %{url}/archive/v%{version}.tar.gz
Patch0: 0001-systemd-services.patch
AutoReq: no AutoReq: no
Conflicts: python-shadowsocks python3-shadowsocks Conflicts: python-shadowsocks python3-shadowsocks
@ -46,7 +45,6 @@ shadowsocks-libev is a lightweight secured scoks5 proxy for embedded devices and
%prep %prep
%setup -q %setup -q
%patch0 -p1
%build %build
./autogen.sh ./autogen.sh
@ -68,9 +66,8 @@ install -m 755 %{_builddir}/%{buildsubdir}/rpm/SOURCES/etc/init.d/shadowsocks-li
%else %else
mkdir -p %{buildroot}%{_sysconfdir}/sysconfig mkdir -p %{buildroot}%{_sysconfdir}/sysconfig
mkdir -p %{buildroot}%{_unitdir} mkdir -p %{buildroot}%{_unitdir}
install -m 644 %{_builddir}/%{buildsubdir}/debian/shadowsocks-libev.default %{buildroot}%{_sysconfdir}/sysconfig/shadowsocks-libev
install -m 644 %{_builddir}/%{buildsubdir}/debian/shadowsocks-libev.service %{buildroot}%{_unitdir}/shadowsocks-libev.service
install -m 644 %{_builddir}/%{buildsubdir}/debian/shadowsocks-libev-*.service %{buildroot}%{_unitdir}/
install -m 644 %{_builddir}/%{buildsubdir}/rpm/SOURCES/systemd/shadowsocks-libev.default %{buildroot}%{_sysconfdir}/sysconfig/shadowsocks-libev
install -m 644 %{_builddir}/%{buildsubdir}/rpm/SOURCES/systemd/shadowsocks-libev*.service %{buildroot}%{_unitdir}/
%endif %endif
install -m 644 %{_builddir}/%{buildsubdir}/debian/config.json %{buildroot}%{_sysconfdir}/shadowsocks-libev/config.json install -m 644 %{_builddir}/%{buildsubdir}/debian/config.json %{buildroot}%{_sysconfdir}/shadowsocks-libev/config.json
@ -134,8 +131,7 @@ fi
%if ! 0%{?use_systemd} %if ! 0%{?use_systemd}
%{_initddir}/shadowsocks-libev %{_initddir}/shadowsocks-libev
%else %else
%{_unitdir}/shadowsocks-libev.service
%{_unitdir}/shadowsocks-libev-*.service
%{_unitdir}/shadowsocks-libev*.service
%config(noreplace) %{_sysconfdir}/sysconfig/shadowsocks-libev %config(noreplace) %{_sysconfdir}/sysconfig/shadowsocks-libev
%endif %endif

31
rpm/genrpm.sh

@ -34,10 +34,10 @@ do
done done
# determine version and release number # determine version and release number
GIT_DESCRIBE=$(git describe --tags --match 'v*' --long --dirty)
GIT_DESCRIBE=$(git describe --tags --match 'v*' --long)
# GIT_DESCRIBE is like v3.0.3-11-g1e3f35c-dirty # GIT_DESCRIBE is like v3.0.3-11-g1e3f35c-dirty
if [[ ! "$GIT_DESCRIBE" =~ ^v([^-]+)-([0-9]+)-g([0-9a-f]+)(-dirty)?$ ]]; then
if [[ ! "$GIT_DESCRIBE" =~ ^v([^-]+)-([0-9]+)-g([0-9a-f]+)$ ]]; then
>&2 echo 'ERROR - unrecognized `git describe` output: '"$GIT_DESCRIBE" >&2 echo 'ERROR - unrecognized `git describe` output: '"$GIT_DESCRIBE"
exit 1 exit 1
fi fi
@ -45,30 +45,31 @@ fi
TARGET_VERSION=${BASH_REMATCH[1]} TARGET_VERSION=${BASH_REMATCH[1]}
TARGET_COMMITS=${BASH_REMATCH[2]} TARGET_COMMITS=${BASH_REMATCH[2]}
TARGET_SHA1=${BASH_REMATCH[3]} TARGET_SHA1=${BASH_REMATCH[3]}
TARGET_DIRTY=${BASH_REMATCH[4]}
TARGET_RELEASE=1 TARGET_RELEASE=1
if [ "$TARGET_COMMITS" -gt 0 ]; then if [ "$TARGET_COMMITS" -gt 0 ]; then
TARGET_RELEASE+=".$TARGET_COMMITS.git$TARGET_SHA1" TARGET_RELEASE+=".$TARGET_COMMITS.git$TARGET_SHA1"
fi fi
if [ -n "$TARGET_DIRTY" ]; then
TARGET_RELEASE+=.dirty
fi
TARGET_VERREL=$TARGET_VERSION-$TARGET_RELEASE TARGET_VERREL=$TARGET_VERSION-$TARGET_RELEASE
>&2 echo "INFO - RPM version-release is $TARGET_VERREL." >&2 echo "INFO - RPM version-release is $TARGET_VERREL."
# archive tarball from Git workspace # archive tarball from Git workspace
TARGET_TARBALL_NAME=shadowsocks-libev-$TARGET_VERSION
TARGET_TARBALL_DIR=$HERE/SOURCES
export TARGET_TARBALL_NAME=shadowsocks-libev-$TARGET_VERSION
export TARGET_TARBALL_DIR=$HERE/SOURCES
mkdir -p -- "$TARGET_TARBALL_DIR" mkdir -p -- "$TARGET_TARBALL_DIR"
#git archive HEAD --format=tar --prefix="$TARGET_TARBALL_NAME/" \
# -o "$TARGET_TARBALL_DIR/$TARGET_TARBALL_NAME.tar"
pushd "$HERE"/.. pushd "$HERE"/..
make clean
tar --exclude './rpm' --exclude '.[^/]*' --transform "s,^\.,$TARGET_TARBALL_NAME," \
-cvf "$TARGET_TARBALL_DIR/$TARGET_TARBALL_NAME.tar" .
# archive this repo
git archive HEAD --format=tar --prefix="$TARGET_TARBALL_NAME/" \
-o "$TARGET_TARBALL_DIR/$TARGET_TARBALL_NAME.tar"
# archive submodules
git submodule update --init
git submodule foreach 'git archive HEAD --format=tar \
--prefix="$TARGET_TARBALL_NAME/$path/" \
-o "$TARGET_TARBALL_DIR/$TARGET_TARBALL_NAME-submodule-$path-$sha1.tar"
tar -n --concatenate --file="$TARGET_TARBALL_DIR/$TARGET_TARBALL_NAME.tar" \
"$TARGET_TARBALL_DIR/$TARGET_TARBALL_NAME-submodule-$path-$sha1.tar"'
gzip -c "$TARGET_TARBALL_DIR/$TARGET_TARBALL_NAME.tar" > "$TARGET_TARBALL_DIR/$TARGET_TARBALL_NAME.tar.gz"
popd popd
# generate spec file # generate spec file
@ -77,7 +78,7 @@ mkdir -p -- "$TARGET_SPEC_DIR"
TARGET_SPEC_PATH=$TARGET_SPEC_DIR/shadowsocks-libev.spec TARGET_SPEC_PATH=$TARGET_SPEC_DIR/shadowsocks-libev.spec
sed -e "s/^\(Version:\).*$/\1 ${TARGET_VERSION}/" \ sed -e "s/^\(Version:\).*$/\1 ${TARGET_VERSION}/" \
-e "s/^\(Release:\).*$/\1 ${TARGET_RELEASE}%{?dist}/" \ -e "s/^\(Release:\).*$/\1 ${TARGET_RELEASE}%{?dist}/" \
-e "s/^\(Source0:\).*$/\1 ${TARGET_TARBALL_NAME}.tar/" \
-e "s/^\(Source0:\).*$/\1 ${TARGET_TARBALL_NAME}.tar.gz/" \
"${TARGET_SPEC_PATH}".in > "${TARGET_SPEC_PATH}" "${TARGET_SPEC_PATH}".in > "${TARGET_SPEC_PATH}"
# build rpms # build rpms

Loading…
Cancel
Save