https://pastein.ru/t/bF
скопируйте уникальную ссылку для отправки
Загрузка данных
#!/bin/sh
#
# 3proxy daemon control script
#
### BEGIN INIT INFO
# Provides: 3proxy
# Required-Start: $network $remote_fs $syslog
# Required-Stop: $network $remote_fs $syslog
# Should-Start: $named
# Should-Stop: $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: 3proxy HTTP Proxy
### END INIT INFO
ScriptName="3proxy"
ScriptFullName="/etc/init.d/3proxy"
ConfigFile="/etc/3proxy/3proxy.cfg"
LogDir="/var/log/3proxy"
PidFile="/tmp/3proxy.pid"
ResourcesData=""
main()
{
LoadResources
if [ ! -d "${LogDir}" ]
then
mkdir -p "${LogDir}";
fi
case "$1" in
start) Start ;;
stop) Stop ;;
restart) Stop; Start ;;
status) Status ;;
*) ShowHelp;;
esac
}
Start()
{
local msg
local ProxyPID
if [ ! -f "${ConfigFile}" ]
then
msg=`GetResource "msgConfigFileNotFound"`
printf "${msg}" "${ConfigFile}"
return
fi
if cat "${ConfigFile}" | grep -qe "^noconfig"
then
msg=`GetResource "msgNoconfigDetected"`
printf "${msg}" "${ConfigFile}"
return
fi
ProxyPID=`Get3proxyPID`
if [ ! -z "${ProxyPID}" ]
then
msg=`GetResource "msg3proxyAlreadyRunning"`
printf "${msg}" "${ProxyPID}"
return
fi
3proxy "${ConfigFile}"
sleep 1
ProxyPID=`Get3proxyPID`
if [ ! -f "${PidFile}" ]
then
msg=`GetResource "msg3proxyStartProblems"`
printf "${msg}"
return
fi
if [ `cat "${PidFile}"` != "${ProxyPID}" ]
then
msg=`GetResource "msg3proxyStartProblems"`
printf "${msg}"
return
fi
msg=`GetResource "msg3proxyStartedSuccessfully"`
printf "${msg}" `date +%d-%m-%Y" "%H:%M:%S` "${ProxyPID}"
}
Stop()
{
local msg
local ProxyPID
ProxyPID=`Get3proxyPID`
if [ -f "${PidFile}" ]
then
if [ `cat "${PidFile}"` = "${ProxyPID}" ]
then
kill -9 "${ProxyPID}"
rm -f "${PidFile}"
msg=`GetResource "msg3proxyStoppedSuccessfully"`
printf "${msg}" `date +%d-%m-%Y" "%H:%M:%S`
return
fi
fi
if [ -z "${ProxyPID}" ]
then
msg=`GetResource "msg3proxyProxyNotDetected"`
printf "${msg}"
return
fi
pkill -o 3proxy
msg=`GetResource "msg3proxyStoppedByKillall"`
printf "${msg}" `date +%d-%m-%Y" "%H:%M:%S` "${PidFile}"
}
Status()
{
local msg
local ProxyPID
if [ -f "${PidFile}" ]
then
msg=`GetResource "msgPidFileExists"`
printf "${msg}" "${PidFile}" `cat "${PidFile}"`
else
msg=`GetResource "msgPidFileNotExists"`
printf "${msg}" "${PidFile}"
fi
ProxyPID=`Get3proxyPID`
if [ ! -z "${ProxyPID}" ]
then
msg=`GetResource "msg3proxyProcessDetected"`
printf "${msg}"
ps -ef | awk '$8 ~ /^3proxy/ { print "User: " $1 "\tPID: " $2 }'
else
msg=`GetResource "msg3proxyProcessNotDetected"`
printf "${msg}"
fi
}
ShowHelp()
{
local msg
msg=`GetResource "msg3proxyHelp"`
printf "${msg}" "${ScriptFullName}" "${ScriptName}"
}
Get3proxyPID()
{
ps -ef | awk '$8 ~ /^3proxy/ { print $2; exit }'
}
LoadResources()
{
local StartRow
local EndRow
local LngLabel
local msgResourceErr="\aError! Script could not find resources!"
if env | grep -q 'LANG=ru_RU.UTF-8'
then
LngLabel="RU"
else
LngLabel="EN"
fi
StartRow=`cat "${ScriptFullName}" | awk "/^#Resources_${LngLabel}/ { print NR; exit}"`
if [ -z "${StartRow}" ]
then
echo -e "${msgResourceErr}"
exit 255
fi
EndRow=`cat "${ScriptFullName}" | awk "NR > ${StartRow} && /^#Resources_${LngLabel}_end/ { print NR; exit}"`
if [ -z "${EndRow}" ]
then
echo -e "${msgResourceErr}"
exit 255
fi
ResourcesData=`cat "${ScriptFullName}" | awk -v StartRow="${StartRow}" -v EndRow="${EndRow}" 'NR > StartRow && NR < EndRow { print $0 }'`
}
# $1 - Name of Resource
GetResource()
{
local StartRow
local EndRow
local msgResourceErr="\aError! Script could not find resource \"${1}\"!"
StartRow=`echo "${ResourcesData}" | awk "/^#Resource=${1}/ { print NR; exit}"`
if [ -z "${StartRow}" ]
then
echo -e "${msgResourceErr}" > /dev/stderr
exit 255
fi
EndRow=`echo "${ResourcesData}" | awk "NR > ${StartRow} && /^#endResource=${1}/ { print NR; exit}"`
if [ -z "${EndRow}" ]
then
echo -e "${msgResourceErr}" > /dev/stderr
exit 255
fi
echo "${ResourcesData}" | awk -v StartRow="${StartRow}" -v EndRow="${EndRow}" 'NR > StartRow && NR < EndRow { print $0 }'
}
main $@
exit 0;
#Resources_EN
#Resource=msg3proxyHelp
Usage:
\t%s {start|stop|restart}
or
\tservice %s {start|stop|restart|status}\\n
#endResource=msg3proxyHelp
#Resource=msgConfigFileNotFound
\a3proxy configuration file - "%s" is not found!\\n
#endResource=msgConfigFileNotFound
#Resource=msgNoconfigDetected
Parameter "noconfig" found in 3proxy configuration file -
"% s" !
To run 3proxy this parameter should be disabled.\\n
#endResource=msgNoconfigDetected
#Resource=msg3proxyAlreadyRunning
\a3proxy already running PID: %s\\n
#endResource=msg3proxyAlreadyRunning
#Resource=msg3proxyStartProblems
With the start of 3proxy, something is wrong!
Use: service 3proxy status\\n
#endResource=msg3proxyStartProblems
#Resource=msg3proxyStartedSuccessfully
[ %s %s ] 3proxy started successfully! PID: %s\\n
#endResource=msg3proxyStartedSuccessfully
#Resource=msg3proxyStoppedSuccessfully
[ %s %s ] 3proxy stopped successfully!\\n
#endResource=msg3proxyStoppedSuccessfully
#Resource=msg3proxyProxyNotDetected
Process "3proxy" is not detected!\\n
#endResource=msg3proxyProxyNotDetected
#Resource=msg3proxyStoppedByKillall
[ %s %s ] Command "pkill -o 3proxy" was executed,
because process number was not stored in "%s",
but in fact 3proxy was runned!\\n
#endResource=msg3proxyStoppedByKillall
#Resource=msgPidFileExists
File "%s" exists. It contains the PID: %s\\n
#endResource=msgPidFileExists
#Resource=msgPidFileNotExists
File "%s" not found, that is, PID 3proxy was not stored!\\n
#endResource=msgPidFileNotExists
#Resource=msg3proxyProcessDetected
Process 3proxy detected:\\n
#endResource=msg3proxyProcessDetected
#Resource=msg3proxyProcessNotDetected
Processes of 3proxy is not found!\\n
#endResource=msg3proxyProcessNotDetected
#Resources_EN_end
#Resources_RU
#Resource=msg3proxyHelp
Используйте:
\t%s {start|stop|restart}
или
\tservice %s {start|stop|restart|status}\\n
#endResource=msg3proxyHelp
#Resource=msgConfigFileNotFound
\aФайл конфигурации 3proxy - "%s", не найден!\\n
#endResource=msgConfigFileNotFound
#Resource=msgNoconfigDetected
\aОбнаружен параметр "noconfig" в файле конфигурации 3proxy -
"%s" !
Для запуска 3proxy этот параметр нужно отключить.\\n
#endResource=msgNoconfigDetected
#Resource=msg3proxyAlreadyRunning
\a3proxy уже запущен PID: %s\\n
#endResource=msg3proxyAlreadyRunning
#Resource=msg3proxyStartProblems
\aСо стартом 3proxy, что-то не так!
Используйте: service 3proxy status\\n
#endResource=msg3proxyStartProblems
#Resource=msg3proxyStartedSuccessfully
[ %s %s ] 3proxy успешно стартовал! PID: %s\\n
#endResource=msg3proxyStartedSuccessfully
#Resource=msg3proxyStoppedSuccessfully
[ %s %s ] 3proxy успешно остановлен!\\n
#endResource=msg3proxyStoppedSuccessfully
#Resource=msg3proxyProxyNotDetected
Процесс "3proxy" не обнаружен!\\n
#endResource=msg3proxyProxyNotDetected
#Resource=msg3proxyStoppedByKillall
[ %s %s ] Выполнена команда "pkill -o 3proxy",
т.к. номер процесса не записан в "%s",
но по факту 3proxy рабатал!\\n
#endResource=msg3proxyStoppedByKillall
#Resource=msgPidFileExists
Файл "%s" есть. Он содержит PID: %s\\n
#endResource=msgPidFileExists
#Resource=msgPidFileNotExists
Файл "%s" не найден, т.е. PID 3proxy не был сохранён!\\n
#endResource=msgPidFileNotExists
#Resource=msg3proxyProcessDetected
Обнаружен процесс 3proxy:\\n
#endResource=msg3proxyProcessDetected
#Resource=msg3proxyProcessNotDetected
Процессов 3proxy не обнаружено!\\n
#endResource=msg3proxyProcessNotDetected
#Resources_RU_end