From 01b2b399a138a9803da8a7b0a6a3105738091021 Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Wed, 6 Jan 2021 11:54:13 +0800 Subject: [PATCH] add systemd service files --- INSTALL | 4 +- client/Makefile.in | 2 +- fastdfs.spec | 47 ++++++++--------- make.sh | 43 +++++++++------- restart.sh | 96 ----------------------------------- stop.sh | 92 --------------------------------- systemd/fdfs_storaged.service | 17 +++++++ systemd/fdfs_trackerd.service | 17 +++++++ 8 files changed, 83 insertions(+), 235 deletions(-) delete mode 100755 restart.sh delete mode 100755 stop.sh create mode 100644 systemd/fdfs_storaged.service create mode 100644 systemd/fdfs_trackerd.service diff --git a/INSTALL b/INSTALL index 3ebb522..0662a8d 100644 --- a/INSTALL +++ b/INSTALL @@ -11,7 +11,7 @@ Chinese language: http://www.fastken.com/ # command lines as: git clone https://github.com/happyfish100/libfastcommon.git - cd libfastcommon; git checkout V1.0.43 + cd libfastcommon; git checkout V1.0.46 ./make.sh clean && ./make.sh && ./make.sh install @@ -21,7 +21,7 @@ Chinese language: http://www.fastken.com/ # command lines as: git clone https://github.com/happyfish100/fastdfs.git - cd fastdfs; git checkout V6.06 + cd fastdfs; git checkout V6.07 ./make.sh clean && ./make.sh && ./make.sh install diff --git a/client/Makefile.in b/client/Makefile.in index 91d3da3..7a1a4b7 100644 --- a/client/Makefile.in +++ b/client/Makefile.in @@ -72,7 +72,7 @@ install: mkdir -p $(TARGET_INC)/fastdfs cp -f $(FDFS_HEADER_FILES) $(TARGET_INC)/fastdfs - if [ ! -f $(CONFIG_PATH)/client.conf.sample ]; then cp -f ../conf/client.conf $(CONFIG_PATH)/client.conf.sample; fi + if [ ! -f $(CONFIG_PATH)/client.conf ]; then cp -f ../conf/client.conf $(CONFIG_PATH)/client.conf; fi clean: rm -f $(ALL_OBJS) $(ALL_PRGS) $(ALL_LIBS) diff --git a/fastdfs.spec b/fastdfs.spec index 135cb6b..91e062f 100644 --- a/fastdfs.spec +++ b/fastdfs.spec @@ -3,6 +3,7 @@ %define FDFSClient libfdfsclient %define FDFSClientDevel libfdfsclient-devel %define FDFSTool fastdfs-tool +%define FDFSConfig fastdfs-config %define FDFSVersion 6.0.7 %define CommitVersion %(echo $COMMIT_VERSION) @@ -26,20 +27,26 @@ commit version: %{CommitVersion} %package -n %{FDFSServer} Requires: libfastcommon >= 1.0.44 +Requires: %{FDFSConfig} Summary: fastdfs tracker & storage %package -n %{FDFSTool} Requires: libfastcommon +Requires: %{FDFSConfig} Summary: fastdfs tools %package -n %{FDFSClient} Requires: libfastcommon +Requires: %{FDFSConfig} Summary: The client dynamic library of fastdfs %package -n %{FDFSClient}-devel Requires: %{FDFSClient} Summary: The client header of fastdfs +%package -n %{FDFSConfig} +Summary: FastDFS config files for sample + %description -n %{FDFSServer} This package provides tracker & storage of fastdfs commit version: %{CommitVersion} @@ -56,31 +63,21 @@ commit version: %{CommitVersion} This package is tools for fastdfs commit version: %{CommitVersion} +%description -n %{FDFSConfig} +FastDFS config files for sample +commit version: %{CommitVersion} + %prep %setup -q %build -# FIXME: I need to fix the upstream Makefile to use LIBDIR et al. properly and -# send the upstream maintainer a patch. -# add DOCDIR to the configure part -./make.sh +./make.sh clean && ./make.sh %install rm -rf %{buildroot} DESTDIR=$RPM_BUILD_ROOT ./make.sh install -#make install IGNORE_MAN_GROUP=y DOC_DIR=%{_docdir}/%{name}-%{version} INIT_DIR=%{_initrddir} -#install -m 0644 sysstat.crond %{buildroot}/%{_sysconfdir}/cron.d/sysstat - -#%find_lang %{name} - -%post -n %{FDFSServer} -/sbin/chkconfig --add fdfs_trackerd -/sbin/chkconfig --add fdfs_storaged - -%preun -n %{FDFSServer} -/sbin/chkconfig --del fdfs_trackerd -/sbin/chkconfig --del fdfs_storaged +%post %postun @@ -88,31 +85,25 @@ DESTDIR=$RPM_BUILD_ROOT ./make.sh install #rm -rf %{buildroot} %files -#%defattr(-,root,root,-) -#/usr/local/bin/* -#/usr/local/include/* %files -n %{FDFSServer} %defattr(-,root,root,-) /usr/bin/fdfs_trackerd /usr/bin/fdfs_storaged -/usr/bin/restart.sh -/usr/bin/stop.sh -/etc/init.d/* -/etc/fdfs/tracker.conf.sample -/etc/fdfs/storage.conf.sample -/etc/fdfs/storage_ids.conf.sample +%config(noreplace) /usr/lib/systemd/system/fdfs_trackerd.service +%config(noreplace) /usr/lib/systemd/system/fdfs_storaged.service %files -n %{FDFSClient} +%defattr(-,root,root,-) /usr/lib64/libfdfsclient* /usr/lib/libfdfsclient* -/etc/fdfs/client.conf.sample %files -n %{FDFSClient}-devel %defattr(-,root,root,-) /usr/include/fastdfs/* %files -n %{FDFSTool} +%defattr(-,root,root,-) /usr/bin/fdfs_monitor /usr/bin/fdfs_test /usr/bin/fdfs_test1 @@ -127,6 +118,10 @@ DESTDIR=$RPM_BUILD_ROOT ./make.sh install /usr/bin/fdfs_upload_appender /usr/bin/fdfs_regenerate_filename +%files -n %{FDFSConfig} +%defattr(-,root,root,-) +%config(noreplace) /etc/fdfs/*.conf + %changelog * Mon Jun 23 2014 Zaixue Liao - first RPM release (1.0) diff --git a/make.sh b/make.sh index 69bb072..cba298a 100755 --- a/make.sh +++ b/make.sh @@ -2,7 +2,7 @@ ENABLE_STATIC_LIB=0 ENABLE_SHARED_LIB=1 TARGET_PREFIX=$DESTDIR/usr TARGET_CONF_PATH=$DESTDIR/etc/fdfs -TARGET_INIT_PATH=$DESTDIR/etc/init.d +TARGET_SYSTEMD_PATH=$DESTDIR/usr/lib/systemd/system WITH_LINUX_SERVICE=1 @@ -154,28 +154,35 @@ perl -pi -e "s#\\\$\(LIBS\)#$LIBS#g" Makefile perl -pi -e "s#\\\$\(TARGET_PREFIX\)#$TARGET_PREFIX#g" Makefile cd .. +copy_file() +{ + src=$1 + dest=$2 + + if [ ! -f $TARGET_CONF_PATH/tracker.conf ]; then + cp -f conf/tracker.conf $TARGET_CONF_PATH/tracker.conf + fi +} + if [ "$1" = "install" ]; then cd .. - cp -f restart.sh $TARGET_PREFIX/bin - cp -f stop.sh $TARGET_PREFIX/bin - if [ "$uname" = "Linux" ]; then if [ "$WITH_LINUX_SERVICE" = "1" ]; then - if [ ! -d /etc/fdfs ]; then - mkdir -p /etc/fdfs - cp -f conf/tracker.conf $TARGET_CONF_PATH/tracker.conf.sample - cp -f conf/storage.conf $TARGET_CONF_PATH/storage.conf.sample - cp -f conf/client.conf $TARGET_CONF_PATH/client.conf.sample - cp -f conf/storage_ids.conf $TARGET_CONF_PATH/storage_ids.conf.sample - cp -f conf/http.conf $TARGET_CONF_PATH/http.conf.sample - cp -f conf/mime.types $TARGET_CONF_PATH/mime.types.sample + if [ ! -d $TARGET_CONF_PATH ]; then + mkdir -p $TARGET_CONF_PATH + cp -f conf/tracker.conf $TARGET_CONF_PATH/tracker.conf + cp -f conf/storage.conf $TARGET_CONF_PATH/storage.conf + cp -f conf/client.conf $TARGET_CONF_PATH/client.conf + cp -f conf/storage_ids.conf $TARGET_CONF_PATH/storage_ids.conf + cp -f conf/http.conf $TARGET_CONF_PATH/http.conf + cp -f conf/mime.types $TARGET_CONF_PATH/mime.types + fi + + if [ ! -f $TARGET_SYSTEMD_PATH/fdfs_trackerd.service ]; then + mkdir -p $TARGET_SYSTEMD_PATH + cp -f systemd/fdfs_trackerd.service $TARGET_SYSTEMD_PATH + cp -f systemd/fdfs_storaged.service $TARGET_SYSTEMD_PATH fi - mkdir -p $TARGET_INIT_PATH - cp -f init.d/fdfs_trackerd $TARGET_INIT_PATH - cp -f init.d/fdfs_storaged $TARGET_INIT_PATH -# /sbin/chkconfig --add fdfs_trackerd -# /sbin/chkconfig --add fdfs_storaged fi fi fi - diff --git a/restart.sh b/restart.sh deleted file mode 100755 index 2b70250..0000000 --- a/restart.sh +++ /dev/null @@ -1,96 +0,0 @@ -#!/bin/sh - -if [ -z "$1" ]; then - /bin/echo "$0 " - exit 1 -fi - -if [ -f /bin/awk ]; then - AWK=/bin/awk -else - AWK=/usr/bin/awk -fi - -if [ -f /bin/grep ]; then - GREP=/bin/grep -else - GREP=/usr/bin/grep -fi - -if [ -f /bin/expr ]; then - EXPR=/bin/expr -else - EXPR=/usr/bin/expr -fi - -if [ -f /bin/sed ]; then - SED=/bin/sed -else - SED=/usr/bin/sed -fi - -program=`/bin/echo $1 | $AWK -F '/' '{print $NF;}'` -param='' -grep_cmd="$GREP -w $program" - -list='2 3 4 5 6 7 8 9' -for i in $list; do - eval p='$'$i - if [ -z "$p" ]; then - break - fi - param="$param $p" - #first_ch=`$EXPR substr "$p" 1 1` - first_ch=`/bin/echo "$p" | $SED -e 's/\(.\).*/\1/'` - if [ "$first_ch" = "-" ]; then - p="'\\$p'" - fi - grep_cmd="$grep_cmd | $GREP -w $p" -done - -cmd="/bin/ps auxww | $grep_cmd | $GREP -v grep | $GREP -v $0 | $AWK '{print \$2;}'" -pids=`/bin/sh -c "$cmd"` -if [ ! -z "$pids" ]; then - i=0 - count=0 - /bin/echo "stopping $program ..." - while [ 1 -eq 1 ]; do - new_pids='' - for pid in $pids; do - if [ $i -eq 0 ]; then - /bin/kill $pid - else - /bin/kill $pid >/dev/null 2>&1 - fi - - if [ $? -eq 0 ]; then - new_pids="$new_pids $pid" - fi - count=`$EXPR $count + 1` - done - - if [ -z "$new_pids" ]; then - break - fi - - pids="$new_pids" - /usr/bin/printf . - /bin/sleep 1 - i=`$EXPR $i + 1` - done -fi - -/bin/echo "" -cmd="/bin/ps auxww | $grep_cmd | $GREP -v grep | $GREP -v $0 | /usr/bin/wc -l" -count=`/bin/sh -c "$cmd"` -if [ $count -eq 0 ]; then - /bin/echo "starting $program ..." - exec $1 $param - exit $? -else - cmd="/bin/ps auxww | $grep_cmd | $GREP -v grep | $GREP -v $0" - /bin/sh -c "$cmd" - /bin/echo "already running $program count: $count, restart aborted!" - exit 16 -fi - diff --git a/stop.sh b/stop.sh deleted file mode 100755 index 6cbdab9..0000000 --- a/stop.sh +++ /dev/null @@ -1,92 +0,0 @@ -#!/bin/sh - -if [ -z "$1" ]; then - /bin/echo "$0 " - exit 1 -fi - -if [ -f /bin/awk ]; then - AWK=/bin/awk -else - AWK=/usr/bin/awk -fi - -if [ -f /bin/grep ]; then - GREP=/bin/grep -else - GREP=/usr/bin/grep -fi - -if [ -f /bin/expr ]; then - EXPR=/bin/expr -else - EXPR=/usr/bin/expr -fi - -if [ -f /bin/sed ]; then - SED=/bin/sed -else - SED=/usr/bin/sed -fi - -program=`/bin/echo $1 | $AWK -F '/' '{print $NF;}'` -grep_cmd="$GREP -w $program" - -list='2 3 4 5 6 7 8 9' -for i in $list; do - eval p='$'$i - if [ -z "$p" ]; then - break - fi - #first_ch=`$EXPR substr "$p" 1 1` - first_ch=`/bin/echo "$p" | $SED -e 's/\(.\).*/\1/'` - if [ "$first_ch" = "-" ]; then - p="'\\$p'" - fi - grep_cmd="$grep_cmd | $GREP -w $p" -done - -cmd="/bin/ps auxww | $grep_cmd | $GREP -v grep | $GREP -v $0 | $AWK '{print \$2;}'" -pids=`/bin/sh -c "$cmd"` -if [ ! -z "$pids" ]; then - i=0 - count=0 - /bin/echo "stopping $program ..." - while [ 1 -eq 1 ]; do - new_pids='' - for pid in $pids; do - if [ $i -eq 0 ]; then - /bin/kill $pid - else - /bin/kill $pid >/dev/null 2>&1 - fi - - if [ $? -eq 0 ]; then - new_pids="$new_pids $pid" - fi - count=`$EXPR $count + 1` - done - - if [ -z "$new_pids" ]; then - break - fi - - pids="$new_pids" - /usr/bin/printf . - /bin/sleep 1 - i=`$EXPR $i + 1` - done -fi - -/bin/echo "" -cmd="/bin/ps auxww | $grep_cmd | $GREP -v grep | $GREP -v $0 | /usr/bin/wc -l" -count=`/bin/sh -c "$cmd"` -if [ $count -eq 0 ]; then - exit 0 -else - cmd="/bin/ps auxww | $grep_cmd | $GREP -v grep | $GREP -v $0" - /bin/sh -c "$cmd" - /bin/echo "already running $program count: $count, stop fail!" - exit 16 -fi - diff --git a/systemd/fdfs_storaged.service b/systemd/fdfs_storaged.service new file mode 100644 index 0000000..900cd30 --- /dev/null +++ b/systemd/fdfs_storaged.service @@ -0,0 +1,17 @@ +[Unit] +Description=FastDFS trackerd service +After=network.target + +[Service] +Type=forking +PIDFile=/opt/fastcfs/data/fdfs_trackerd.pid +ExecStart=/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart + +# No artificial start/stop timeout +TimeoutSec=0 + +# Disable OOM kill by Linux kernel +OOMScoreAdjust=-1000 + +[Install] +WantedBy=multi-user.target diff --git a/systemd/fdfs_trackerd.service b/systemd/fdfs_trackerd.service new file mode 100644 index 0000000..3a5197d --- /dev/null +++ b/systemd/fdfs_trackerd.service @@ -0,0 +1,17 @@ +[Unit] +Description=FastDFS storaged service +After=network.target + +[Service] +Type=forking +PIDFile=/opt/fastcfs/data/fdfs_storaged.pid +ExecStart=/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart + +# No artificial start/stop timeout +TimeoutSec=0 + +# Disable OOM kill by Linux kernel +OOMScoreAdjust=-1000 + +[Install] +WantedBy=multi-user.target