Всем приветствую.
Возникла такая необходимость, надо перевести с одного сервика скрипт на другой.
Буду признателен если кто сможет на некоторых правках пояснить чем они похожи.
Ниже привожу скрипт, заранее благодарю.
Рабочий скрипт, тот что требуется переделать
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Veeam Agent for Linux service"
NAME=veeamservice
DAEMON=/usr/sbin/$NAME
PIDFILE=/var/run/$NAME.pid
DAEMON_ARGS="--daemonize --pidfile=$PIDFILE"
SCRIPTNAME=/etc/init.d/$NAME
MODULE_NAME="veeamsnap"
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS \
|| return 2
# Add code here, if necessary, that waits for the process to be ready
# to handle requests from services started subsequently which depend
# on this one. As a last resort, sleep for some time.
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
#reload|force-reload)
#
# If do_reload() is not implemented then leave this commented out
# and leave 'force-reload' as an alias for 'restart'.
#
#log_daemon_msg "Reloading $DESC" "$NAME"
#do_reload
#log_end_msg $?
#;;
upgrade)
do_upgrade
;;
restart|force-reload)
#
# If the "reload" option is implemented then remove the
# 'force-reload' alias
#
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $SCRIPTNAME {start|stop|status|restart|upgrade|force-reload}" >&2
exit 3
;;
esac
А это что я нашел в инете пример
# This service only runs as root
[ "$(id -u)" = 0 ] && {
PreCmd="/bin/su - ${USER} -c"
} || {
echo $0 must run as root.
exit 1
}
# CMD is the actual command that runs the service (e.g. httpd)
SERVICE_DIR=/opt/sample_script
CMD="$SERVICE_DIR/sample_service"
SERVICE_NAME=SampleService
PID_FILE_DIR=/var/run/sample_service
PID_FILE=${PID_FILE_DIR}/sample.pid
LOGFILE=/var/logs/sample_service.log
LOGFILEDATE=`date '+%F:%T'`
USER=sample_user
USAGE_TEXT="Usage: $0 start|stop|restart|status"
start_service () {
if [ ! -f $PID_FILE ]; then
echo -n "Starting $SERVICE_NAME... "
PID=`${PreCmd} "nohup $CMD >> ${LOGFILE} 2>&1 </dev/null & echo \\\$! "`
echo $PID > $PID_FILE
chown $USER:$USER $PID_FILE
echo "Started!"
${PreCmd} "echo $0: $SERVICE_NAME startup $LOGFILEDATE" >> "${LOGFILE}"
else
echo "$SERVICE_NAME is already running. PID file exists."
fi
}
stop_service () {
status_service do_stop
}
status_service () {
SERVICE_STATUS=""
if [ -f $PID_FILE ]; then
PID=$(cat $PID_FILE);
if [ "$PID" = "" ]; then
echo "$SERVICE_NAME is in an unknown state. Please restart. "
else
is_running=`ps -e | grep $PID | wc -l`
if [ "$is_running" = "1" ]; then
if [ "$1" = "" ]; then
# this is just status
echo "$SERVICE_NAME is running"
else
if [ "$1" = "do_stop" ]; then
echo -n "$SERVICE_NAME stopping... "
kill "$PID"
echo "Stopped!"
rm $PID_FILE
${PreCmd} "echo $0: [$LOGFILEDATE] $SERVICE_NAME shutdown" >> "${LOGFILE}"
fi
fi
else
rm $PID_FILE
echo "$SERVICE_NAME is not running. PID file cleaned up."
fi
fi
else
echo "$SERVICE_NAME is not running."
fi
}
[ "$1" = "" ] && {
echo $USAGE_TEXT
echo ""
exit 1
}
[ -d ${PID_FILE_DIR} ] || {
mkdir -p $PID_FILE_DIR
chown $USER:$USER $PID_FILE_DIR
}
case $1 in
start)
cd ${SERVICE_DIR}
start_service && sleep 1
;;
stop)
stop_service
;;
restart)
stop_service
sleep 2
start_service && sleep 1
;;
status)
status_service
esac
Заранее балгодарю.