add systemd service files

pull/487/head
YuQing 2021-01-06 11:54:13 +08:00
parent d1d3e54781
commit 01b2b399a1
8 changed files with 83 additions and 235 deletions

View File

@ -11,7 +11,7 @@ Chinese language: http://www.fastken.com/
# command lines as: # command lines as:
git clone https://github.com/happyfish100/libfastcommon.git 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 ./make.sh clean && ./make.sh && ./make.sh install
@ -21,7 +21,7 @@ Chinese language: http://www.fastken.com/
# command lines as: # command lines as:
git clone https://github.com/happyfish100/fastdfs.git 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 ./make.sh clean && ./make.sh && ./make.sh install

View File

@ -72,7 +72,7 @@ install:
mkdir -p $(TARGET_INC)/fastdfs mkdir -p $(TARGET_INC)/fastdfs
cp -f $(FDFS_HEADER_FILES) $(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: clean:
rm -f $(ALL_OBJS) $(ALL_PRGS) $(ALL_LIBS) rm -f $(ALL_OBJS) $(ALL_PRGS) $(ALL_LIBS)

View File

@ -3,6 +3,7 @@
%define FDFSClient libfdfsclient %define FDFSClient libfdfsclient
%define FDFSClientDevel libfdfsclient-devel %define FDFSClientDevel libfdfsclient-devel
%define FDFSTool fastdfs-tool %define FDFSTool fastdfs-tool
%define FDFSConfig fastdfs-config
%define FDFSVersion 6.0.7 %define FDFSVersion 6.0.7
%define CommitVersion %(echo $COMMIT_VERSION) %define CommitVersion %(echo $COMMIT_VERSION)
@ -26,20 +27,26 @@ commit version: %{CommitVersion}
%package -n %{FDFSServer} %package -n %{FDFSServer}
Requires: libfastcommon >= 1.0.44 Requires: libfastcommon >= 1.0.44
Requires: %{FDFSConfig}
Summary: fastdfs tracker & storage Summary: fastdfs tracker & storage
%package -n %{FDFSTool} %package -n %{FDFSTool}
Requires: libfastcommon Requires: libfastcommon
Requires: %{FDFSConfig}
Summary: fastdfs tools Summary: fastdfs tools
%package -n %{FDFSClient} %package -n %{FDFSClient}
Requires: libfastcommon Requires: libfastcommon
Requires: %{FDFSConfig}
Summary: The client dynamic library of fastdfs Summary: The client dynamic library of fastdfs
%package -n %{FDFSClient}-devel %package -n %{FDFSClient}-devel
Requires: %{FDFSClient} Requires: %{FDFSClient}
Summary: The client header of fastdfs Summary: The client header of fastdfs
%package -n %{FDFSConfig}
Summary: FastDFS config files for sample
%description -n %{FDFSServer} %description -n %{FDFSServer}
This package provides tracker & storage of fastdfs This package provides tracker & storage of fastdfs
commit version: %{CommitVersion} commit version: %{CommitVersion}
@ -56,31 +63,21 @@ commit version: %{CommitVersion}
This package is tools for fastdfs This package is tools for fastdfs
commit version: %{CommitVersion} commit version: %{CommitVersion}
%description -n %{FDFSConfig}
FastDFS config files for sample
commit version: %{CommitVersion}
%prep %prep
%setup -q %setup -q
%build %build
# FIXME: I need to fix the upstream Makefile to use LIBDIR et al. properly and ./make.sh clean && ./make.sh
# send the upstream maintainer a patch.
# add DOCDIR to the configure part
./make.sh
%install %install
rm -rf %{buildroot} rm -rf %{buildroot}
DESTDIR=$RPM_BUILD_ROOT ./make.sh install 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 %post
#%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
%postun %postun
@ -88,31 +85,25 @@ DESTDIR=$RPM_BUILD_ROOT ./make.sh install
#rm -rf %{buildroot} #rm -rf %{buildroot}
%files %files
#%defattr(-,root,root,-)
#/usr/local/bin/*
#/usr/local/include/*
%files -n %{FDFSServer} %files -n %{FDFSServer}
%defattr(-,root,root,-) %defattr(-,root,root,-)
/usr/bin/fdfs_trackerd /usr/bin/fdfs_trackerd
/usr/bin/fdfs_storaged /usr/bin/fdfs_storaged
/usr/bin/restart.sh %config(noreplace) /usr/lib/systemd/system/fdfs_trackerd.service
/usr/bin/stop.sh %config(noreplace) /usr/lib/systemd/system/fdfs_storaged.service
/etc/init.d/*
/etc/fdfs/tracker.conf.sample
/etc/fdfs/storage.conf.sample
/etc/fdfs/storage_ids.conf.sample
%files -n %{FDFSClient} %files -n %{FDFSClient}
%defattr(-,root,root,-)
/usr/lib64/libfdfsclient* /usr/lib64/libfdfsclient*
/usr/lib/libfdfsclient* /usr/lib/libfdfsclient*
/etc/fdfs/client.conf.sample
%files -n %{FDFSClient}-devel %files -n %{FDFSClient}-devel
%defattr(-,root,root,-) %defattr(-,root,root,-)
/usr/include/fastdfs/* /usr/include/fastdfs/*
%files -n %{FDFSTool} %files -n %{FDFSTool}
%defattr(-,root,root,-)
/usr/bin/fdfs_monitor /usr/bin/fdfs_monitor
/usr/bin/fdfs_test /usr/bin/fdfs_test
/usr/bin/fdfs_test1 /usr/bin/fdfs_test1
@ -127,6 +118,10 @@ DESTDIR=$RPM_BUILD_ROOT ./make.sh install
/usr/bin/fdfs_upload_appender /usr/bin/fdfs_upload_appender
/usr/bin/fdfs_regenerate_filename /usr/bin/fdfs_regenerate_filename
%files -n %{FDFSConfig}
%defattr(-,root,root,-)
%config(noreplace) /etc/fdfs/*.conf
%changelog %changelog
* Mon Jun 23 2014 Zaixue Liao <liaozaixue@yongche.com> * Mon Jun 23 2014 Zaixue Liao <liaozaixue@yongche.com>
- first RPM release (1.0) - first RPM release (1.0)

47
make.sh
View File

@ -2,7 +2,7 @@ ENABLE_STATIC_LIB=0
ENABLE_SHARED_LIB=1 ENABLE_SHARED_LIB=1
TARGET_PREFIX=$DESTDIR/usr TARGET_PREFIX=$DESTDIR/usr
TARGET_CONF_PATH=$DESTDIR/etc/fdfs 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 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 perl -pi -e "s#\\\$\(TARGET_PREFIX\)#$TARGET_PREFIX#g" Makefile
cd .. 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 if [ "$1" = "install" ]; then
cd .. cd ..
cp -f restart.sh $TARGET_PREFIX/bin
cp -f stop.sh $TARGET_PREFIX/bin
if [ "$uname" = "Linux" ]; then if [ "$uname" = "Linux" ]; then
if [ "$WITH_LINUX_SERVICE" = "1" ]; then if [ "$WITH_LINUX_SERVICE" = "1" ]; then
if [ ! -d /etc/fdfs ]; then if [ ! -d $TARGET_CONF_PATH ]; then
mkdir -p /etc/fdfs mkdir -p $TARGET_CONF_PATH
cp -f conf/tracker.conf $TARGET_CONF_PATH/tracker.conf.sample cp -f conf/tracker.conf $TARGET_CONF_PATH/tracker.conf
cp -f conf/storage.conf $TARGET_CONF_PATH/storage.conf.sample cp -f conf/storage.conf $TARGET_CONF_PATH/storage.conf
cp -f conf/client.conf $TARGET_CONF_PATH/client.conf.sample cp -f conf/client.conf $TARGET_CONF_PATH/client.conf
cp -f conf/storage_ids.conf $TARGET_CONF_PATH/storage_ids.conf.sample cp -f conf/storage_ids.conf $TARGET_CONF_PATH/storage_ids.conf
cp -f conf/http.conf $TARGET_CONF_PATH/http.conf.sample cp -f conf/http.conf $TARGET_CONF_PATH/http.conf
cp -f conf/mime.types $TARGET_CONF_PATH/mime.types.sample cp -f conf/mime.types $TARGET_CONF_PATH/mime.types
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 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
fi
fi
fi

View File

@ -1,96 +0,0 @@
#!/bin/sh
if [ -z "$1" ]; then
/bin/echo "$0 <command line>"
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

92
stop.sh
View File

@ -1,92 +0,0 @@
#!/bin/sh
if [ -z "$1" ]; then
/bin/echo "$0 <command line>"
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

View File

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

View File

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