service: init.d script

This commit is contained in:
Zhang Qiang 2017-06-08 10:24:23 +08:00
parent 181e0103e4
commit 49e77cfa20
3 changed files with 168 additions and 0 deletions

146
dist/master/init.d/master vendored Executable file
View File

@ -0,0 +1,146 @@
#!/bin/sh
#
#set -x
# acl_master Start/Stop the acl_master daemon.
#
# chkconfig: 2345 90 60
# description: acl master framework
### BEGIN INIT INFO
# Provides: acl_master crontab
# Required-Start: $local_fs $syslog
# Required-Stop: $local_fs $syslog
# Default-Start: 2345
# Default-Stop: 90
# Short-Description: acl - master framework to control services
### END INIT INFO
RETVAL=0
prog="acl_master"
HOME_PATH={install_path}
exec=$HOME_PATH/libexec/acl_master
PROG_NAME=acl_master
PID_FILE=$HOME_PATH/var/pid/acl_master.pid
EXE_PATH=$HOME_PATH/libexec/$PROG_NAME
CONF_PATH=$HOME_PATH/conf
LOG_PATH=$HOME_PATH/var/log/acl_master
lockfile=/var/lock/subsys/acl_master
# Source function library.
. /etc/rc.d/init.d/functions
# A function to find the pid of a program. Looks *only* at the pidfile
findpidfileofproc() {
local pid
# Test syntax.
if [ "$#" = 0 ] ; then
echo $"Usage: pidfileofproc {program}"
return 1
fi
__pids_var_run "$1" "$2"
[ -n "$pid" ] && echo $pid
return 0
}
start() {
if [ $UID -ne 0 ] ; then
echo "User has insufficient privilege."
exit 4
fi
[ -x $exec ] || exit 5
echo -n $"Starting $prog: "
daemon $prog -c $CONF_PATH -l $LOG_PATH &
sleep 1
rh_status_q && success
echo
retval=$?
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
if [ $UID -ne 0 ] ; then
echo "User has insufficient privilege."
exit 4
fi
echo -n $"Stopping $prog: "
if [ -n "`findpidfileofproc $exec $PID_FILE`" ]; then
killproc -p $PID_FILE -d 3 $exec
RETVAL=3
else
failure $"Stopping $prog"
fi
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}
reload() {
echo -n $"Reloading $prog: "
if [ -n "`findpidfileofproc $exec $PID_FILE`" ]; then
killproc $exec -HUP
else
failure $"Reloading $prog"
fi
retval=$?
echo
}
force_reload() {
# new configuration takes effect after restart
restart
}
rh_status() {
# run checks to determine if the service is running or use generic status
status -p $PID_FILE $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
masterrestart|try-restart)
rh_status_q || exit 0
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
esac
exit $?

View File

@ -142,6 +142,7 @@ SBIN_PATH=$PREFIX_PATH$INSTALL_PATH/sbin
CONF_PATH=$PREFIX_PATH$INSTALL_PATH/conf
SERVICE_PATH=$PREFIX_PATH$INSTALL_PATH/conf/service
LIBEXEC_PATH=$PREFIX_PATH$INSTALL_PATH/libexec
INIT_PATH=$PREFIX_PATH/etc/init.d/
SH_PATH=$PREFIX_PATH$INSTALL_PATH/sh
VAR_PATH=$PREFIX_PATH$INSTALL_PATH/var
@ -161,6 +162,7 @@ create_all_path()
create_path $VAR_PATH/pid
create_path $VAR_PATH/private
create_path $VAR_PATH/public
create_path $INIT_PATH
chmod 700 $VAR_PATH/private
chmod 1777 $VAR_PATH/log
@ -175,6 +177,7 @@ copy_all_file()
install_file a+x,go-wrx conf $CONF_PATH
install_file a+x,go-wrx conf/service $SERVICE_PATH
install_file a+x,go-wrx conf/service/samples $SERVICE_PATH/samples
install_file a+x,go-wrx init.d/ $INIT_PATH
}
guess_os

View File

@ -35,9 +35,27 @@ make build_one -j 32
%install
make packinstall DESTDIR=$RPM_BUILD_ROOT
%clean
rm -rf %{buildroot}
%post -n acl-master
/sbin/chkconfig --add master
%preun -n acl-master
if [ "$1" = "0" ]; then
service master stop >/dev/null 2>&1 ||:
/sbin/chkconfig --del master
fi
%postun -n acl-master
if [ "$1" -ge "1" ]; then
# TODO: upgrade should be support
service master masterrestart > /dev/null 2>&1 ||:
fi
%files
%defattr(-,root,root,-)
# TODO: should be renamed
@ -49,3 +67,4 @@ rm -rf %{buildroot}
%files -n acl-master
%defattr(-,root,root)
/opt/soft
/etc/init.d/master