Jump to content

Пользователи, группы...


Recommended Posts

добрый день. подскажите, никак не найду, как запустить приложение (службу) (пример - privoxy) не от рута, а от другого пользователя, если в самом приложении такой настройки нет? в файле /etc/init.d/S24privoxy и других нет такой настройки... например systemd юнитах это  как-то так [service] USER=privoxy GROUP privoxy; а как это сделать в entware?

Edited by Hotery
Link to comment
Share on other sites

privoxy --help

~ # chmod 666 /opt/etc/privoxy/config 
~ # 
~ # chmod 666 /opt/var/log/privoxy.log 
~ # 
~ # /opt/etc/init.d/S24privoxy start
 Starting privoxy...              done. 
~ # 
~ # /opt/etc/init.d/S24privoxy status
 Checking privoxy...              alive. 
~ # 
~ # ps | grep -v grep | grep priv
20658 test      3980 S    privoxy --user test /opt/etc/privoxy/config
~ # 

---

через обёртку

~ # 
~ # id test
uid=10(test) gid=10(test) groups=10(test)
~ # 
~ # /opt/etc/init.d/S24privoxy stop
 Checking privoxy...              alive. 
 Shutting down privoxy...              done. 
~ # 
~ # ps | grep -v grep | grep priv
~ # 
~ # privoxy-su /opt/etc/privoxy/config 
~ # 
~ # ps | grep -v grep | grep priv
21646 test      3844 S    privoxy /opt/etc/privoxy/config
~ # 
~ # /opt/etc/init.d/S24privoxy status
 Checking privoxy...              alive. 
~ # 
~ # cat /opt/bin/privoxy-su 
#!/opt/bin/sh

exec su test -p -c "privoxy $1 $2 $3 $4"
~ # 

===

чтоб два раза не вставать - обратный финт ушами...

/opt $ id
uid=10000(tester) gid=10000(tester) groups=10000(tester)
/opt $ 
/opt $ /opt/etc/init.d/S24privoxy status
 Checking privoxy...              dead. 
/opt $ 
/opt $ privoxy-su /opt/etc/privoxy/config
/opt $ 
/opt $ /opt/etc/init.d/S24privoxy status
 Checking privoxy...              alive. 
/opt $ 
~ # cat /opt/bin/privoxy-su 
#!/opt/bin/sh -x

exec echo keenetic | su -p -m root -c "/opt/sbin/privoxy $1 $2 $3 $4"
~ # 

 

Edited by TheBB
add2
Link to comment
Share on other sites

спасибо! чтот застрял...

cat /opt/usr/sbin/privoxy-su

#!/opt/bin/sh

su privoxy -p -c "privoxy $1 $2 $3 $4"

так запускается: privoxy-su /opt/etc/privoxy (процесс в ps w есть)

а если в /opt/etc/init.d/S24privoxy написать PROCS=privoxy-su - не запускается

~ # /opt/etc/init.d/S24privoxy start
 Starting privoxy-su...              failed.

кажется оно не уходит в background... присобачил перед "su ..." sudo -b" и заработало но наверно как-то криво. как правильно?

 

Link to comment
Share on other sites

1 час назад, Hotery сказал:

как правильно?

правильно - через ключ "--user"

---

~ # 
~ # /opt/etc/init.d/S24privoxy start
 Starting privoxy...              done. 
~ # 
~ # /opt/etc/init.d/S24privoxy status
 Checking privoxy...              alive. 
~ # 
~ # ps | grep -v grep | grep priv
15059 root      3844 S    privoxy /opt/etc/privoxy/config
~ # 
~ # /opt/etc/init.d/S24privoxy stop
 Checking privoxy...              alive. 
 Shutting down privoxy...              done. 
~ # 
~ # chown -R privoxy:privoxy /opt/etc/privoxy
~ # 
~ # chown privoxy:privoxy /opt/var/log/privoxy.log 
~ # 
~ # /opt/etc/init.d/S24privoxy start
 Starting privoxy...              done. 
~ # 
~ # /opt/etc/init.d/S24privoxy status
 Checking privoxy...              alive. 
~ # 
~ # ps | grep -v grep | grep priv
15164 privoxy   3980 S    privoxy --user privoxy /opt/etc/privoxy/config
~ #

===

~ # start-stop-daemon 
BusyBox v1.33.1 (2021-07-08 20:18:22 UTC) multi-call binary.

Usage: start-stop-daemon [OPTIONS] [-S|-K] ... [-- ARGS...]

Search for matching processes, and then
-K: stop all matching processes
-S: start a process unless a matching process is found

Process matching:
	-u USERNAME|UID	Match only this user's processes
	-n NAME		Match processes with NAME
			in comm field in /proc/PID/stat
	-x EXECUTABLE	Match processes with this command
			in /proc/PID/cmdline
	-p FILE		Match a process with PID from FILE
	All specified conditions must match
-S only:
	-x EXECUTABLE	Program to run
	-a NAME		Zeroth argument
	-b		Background
	-c USER[:[GRP]]	Change user/group
	-m		Write PID to pidfile specified by -p
-K only:
	-s SIG		Signal to send
	-t		Match only, exit with 0 if found
Other:
	-q		Quiet
~ #

 

Edited by TheBB
add2
Link to comment
Share on other sites

16 часов назад, Hotery сказал:

спасибо! чтот застрял...

Это всего лишь вариации на тему...

~ # /opt/etc/init.d/S20privoxy start
starting privoxy
~ # /opt/etc/init.d/S20privoxy status
privoxy already running
~ # /opt/etc/init.d/S20privoxy restart
stopping privoxy
starting privoxy
~ # /opt/etc/init.d/S20privoxy check
privoxy already running
~ # ps | grep -v grep | grep priv
31153 privoxy   3844 S    /opt/sbin/privoxy --pidfile /opt/tmp/privoxy.pid /opt/etc/privoxy/config
~ # /opt/etc/init.d/S20privoxy stop
stopping privoxy
~ # /opt/etc/init.d/S20privoxy status
privoxy is not running
~ # 
~ # 
~ # cat /opt/etc/init.d/S20privoxy 
#!/bin/sh

PATH=/opt/sbin:/opt/bin

PIDFILE="/opt/tmp/privoxy.pid"
PROGRAM="privoxy"
PROGRAM_BIN="/opt/sbin/$PROGRAM"
USER="$PROGRAM"

OK="$PROGRAM already running"
NO="$PROGRAM is not running"

status_check ()
{
	[ -f $PIDFILE ] && [ -d /proc/"$(pidof $PROGRAM)" ]
}

start()
{
	su "$USER" -m -p -c "$PROGRAM_BIN --pidfile $PIDFILE /opt/etc/privoxy/config" && echo starting $PROGRAM
}

stop()
{
	kill "$(pidof $PROGRAM)" && echo stopping $PROGRAM
}
case "$1" in
	start)
		if status_check
		then
			echo $OK
		else
			start
		fi
		;;
	stop)
		if status_check
		then
			stop
		else
			echo $NO
		fi
		;;
	check|status)
		if status_check
		then
			echo $OK
		else
			echo $NO
		fi
		;;

	restart)
		stop
		sleep 3
		start
		;;
	*)
		echo "Usage: $0 {start|stop|restart|status}"
		;;
esac
~ #

 

Link to comment
Share on other sites

Продолжим глумиться над пользователями, группами, правами доступа, запуском... )))

Для наглядности, запуск с отладкой - "#!/opt/bin/sh -x" (прошивочный sh так не умеет)

USER=GROUP=privoxy

Скрытый текст
~ # 
~ # 
~ # 
~ # /opt/etc/init.d/S24privoxy start
+ USER=privoxy
+ ENABLED=yes
+ PROCS=privoxy
+ . /opt/etc/init.d/protector
+ protect
+ local 'USER=privoxy'
+ local 'GROUP=privoxy'
+ HOMEDIR=/opt/tmp/privoxy
+ CONFDIR=/opt/tmp/privoxy/conf
+ LOGDIR=/opt/tmp/privoxy/log
+ LOGFILE=/opt/tmp/privoxy/log/privoxy.log
+ PIDDIR=/opt/tmp/privoxy/run
+ PIDFILE=/opt/tmp/privoxy/run/privoxy.pid
+ '[' -d /opt/tmp/privoxy ]
+ mkdir -p /opt/tmp/privoxy
+ chown privoxy:privoxy /opt/tmp/privoxy
+ '[' -d /opt/tmp/privoxy/conf ]
+ mkdir -p /opt/tmp/privoxy/conf
+ cp -R /opt/etc/privoxy/config /opt/etc/privoxy/config-opkg /opt/etc/privoxy/default.action /opt/etc/privoxy/default.filter /opt/etc/privoxy/match-all.action /opt/etc/privoxy/regression-tests.action /opt/etc/privoxy/templates /opt/etc/privoxy/user.action /opt/etc/privoxy/user.filter /opt/etc/privoxy/user.trust /opt/tmp/privoxy/conf/
+ chown -R privoxy:privoxy /opt/tmp/privoxy/conf
+ '[' -d /opt/tmp/privoxy/log ]
+ mkdir -p /opt/tmp/privoxy/log
+ touch /opt/tmp/privoxy/log/privoxy.log
+ chown -R privoxy:privoxy /opt/tmp/privoxy/log
+ chmod 644 /opt/tmp/privoxy/log/privoxy.log
+ '[' -d /opt/tmp/privoxy/run ]
+ mkdir -p /opt/tmp/privoxy/run
+ chown -R privoxy:privoxy /opt/tmp/privoxy/run
+ ARGS='--pidfile /opt/tmp/privoxy/run/privoxy.pid --user privoxy /opt/tmp/privoxy/conf/config'
+ PREARGS=
+ DESC=privoxy
+ PATH=/opt/sbin:/opt/bin
+ . /opt/etc/init.d/rc.func
+ ACTION=start
+ CALLER=
+ ansi_red='\033[1;31m'
+ ansi_white='\033[1;37m'
+ ansi_green='\033[1;32m'
+ ansi_yellow='\033[1;33m'
+ ansi_blue='\033[1;34m'
+ ansi_bell='\007'
+ ansi_blink='\033[5m'
+ ansi_std='\033[m'
+ ansi_rev='\033[7m'
+ ansi_ul='\033[4m'
+ start
+ '['  '!=' yes -a  '=' cron ]
+ '[' yes '!=' yes ]
+ echo -e -n '\033[1;37m Starting privoxy... \033[m'
 Starting privoxy... + pidof privoxy
+ '[' -n  ]
+ 
+ COUNTER=0
+ LIMIT=10
+ privoxy --pidfile /opt/tmp/privoxy/run/privoxy.pid --user privoxy /opt/tmp/privoxy/conf/config
+ pidof privoxy
+ '[' -z 27774 -a 0 -le 10 ]
+ 
+ pidof privoxy
+ '[' -z '27776 27774' ]
+ echo -e '            \033[1;32m done. \033[m'
             done. 
+ logger 'Started privoxy from .'
+ return 0
+ '[' start '=' stop ]
~ # 
~ # 
~ # ps | grep -v grep | grep priv
27776 privoxy   3984 S    privoxy --pidfile /opt/tmp/privoxy/run/privoxy.pid --user privoxy /opt/tmp/privoxy/conf/config
~ # 
~ # /opt/etc/init.d/S24privoxy status
+ USER=privoxy
+ ENABLED=yes
+ PROCS=privoxy
+ . /opt/etc/init.d/protector
+ protect
+ local 'USER=privoxy'
+ local 'GROUP=privoxy'
+ HOMEDIR=/opt/tmp/privoxy
+ CONFDIR=/opt/tmp/privoxy/conf
+ LOGDIR=/opt/tmp/privoxy/log
+ LOGFILE=/opt/tmp/privoxy/log/privoxy.log
+ PIDDIR=/opt/tmp/privoxy/run
+ PIDFILE=/opt/tmp/privoxy/run/privoxy.pid
+ '[' -d /opt/tmp/privoxy ]
+ '[' -d /opt/tmp/privoxy/conf ]
+ '[' -d /opt/tmp/privoxy/log ]
+ '[' -d /opt/tmp/privoxy/run ]
+ ARGS='--pidfile /opt/tmp/privoxy/run/privoxy.pid --user privoxy /opt/tmp/privoxy/conf/config'
+ PREARGS=
+ DESC=privoxy
+ PATH=/opt/sbin:/opt/bin
+ . /opt/etc/init.d/rc.func
+ ACTION=status
+ CALLER=
+ ansi_red='\033[1;31m'
+ ansi_white='\033[1;37m'
+ ansi_green='\033[1;32m'
+ ansi_yellow='\033[1;33m'
+ ansi_blue='\033[1;34m'
+ ansi_bell='\007'
+ ansi_blink='\033[5m'
+ ansi_std='\033[m'
+ ansi_rev='\033[7m'
+ ansi_ul='\033[4m'
+ check
+ echo -e -n '\033[1;37m Checking privoxy... '
 Checking privoxy... + pidof privoxy
+ '[' -n 27776 ]
+ echo -e '            \033[1;32m alive. \033[m'
             alive. 
+ return 0
+ '[' status '=' stop ]
~ # 
~ # /opt/etc/init.d/S24privoxy restart
+ USER=privoxy
+ ENABLED=yes
+ PROCS=privoxy
+ . /opt/etc/init.d/protector
+ protect
+ local 'USER=privoxy'
+ local 'GROUP=privoxy'
+ HOMEDIR=/opt/tmp/privoxy
+ CONFDIR=/opt/tmp/privoxy/conf
+ LOGDIR=/opt/tmp/privoxy/log
+ LOGFILE=/opt/tmp/privoxy/log/privoxy.log
+ PIDDIR=/opt/tmp/privoxy/run
+ PIDFILE=/opt/tmp/privoxy/run/privoxy.pid
+ '[' -d /opt/tmp/privoxy ]
+ '[' -d /opt/tmp/privoxy/conf ]
+ '[' -d /opt/tmp/privoxy/log ]
+ '[' -d /opt/tmp/privoxy/run ]
+ ARGS='--pidfile /opt/tmp/privoxy/run/privoxy.pid --user privoxy /opt/tmp/privoxy/conf/config'
+ PREARGS=
+ DESC=privoxy
+ PATH=/opt/sbin:/opt/bin
+ . /opt/etc/init.d/rc.func
+ ACTION=restart
+ CALLER=
+ ansi_red='\033[1;31m'
+ ansi_white='\033[1;37m'
+ ansi_green='\033[1;32m'
+ ansi_yellow='\033[1;33m'
+ ansi_blue='\033[1;34m'
+ ansi_bell='\007'
+ ansi_blink='\033[5m'
+ ansi_std='\033[m'
+ ansi_rev='\033[7m'
+ ansi_ul='\033[4m'
+ check
+ echo -e -n '\033[1;37m Checking privoxy... '
+ pidof privoxy
+ '[' -n 27776 ]
+ echo -e '            \033[1;32m alive. \033[m'
+ return 0
+ stop
+ echo -e -n '\033[1;37m Shutting down privoxy... \033[m'
 Shutting down privoxy... + killall privoxy
+ COUNTER=0
+ LIMIT=10
+ pidof privoxy
+ '[' -n  -a 0 -le 10 ]
+ pidof privoxy
+ '[' -n  ]
+ echo -e '            \033[1;32m done. \033[m'
             done. 
+ return 0
+ start
+ '['  '!=' yes -a  '=' cron ]
+ '[' yes '!=' yes ]
+ echo -e -n '\033[1;37m Starting privoxy... \033[m'
 Starting privoxy... + pidof privoxy
+ '[' -n  ]
+ 
+ COUNTER=0
+ LIMIT=10
+ privoxy --pidfile /opt/tmp/privoxy/run/privoxy.pid --user privoxy /opt/tmp/privoxy/conf/config
+ pidof privoxy
+ '[' -z 27849 -a 0 -le 10 ]
+ 
+ pidof privoxy
+ '[' -z '27851 27849' ]
+ echo -e '            \033[1;32m done. \033[m'
             done. 
+ logger 'Started privoxy from .'
+ return 0
+ '[' restart '=' stop ]
~ # 
~ # 
~ # 
~ # ps | grep -v grep | grep priv
27851 privoxy   3984 S    privoxy --pidfile /opt/tmp/privoxy/run/privoxy.pid --user privoxy /opt/tmp/privoxy/conf/config
~ # 
~ # /opt/etc/init.d/S24privoxy stop
+ USER=privoxy
+ ENABLED=yes
+ PROCS=privoxy
+ . /opt/etc/init.d/protector
+ protect
+ local 'USER=privoxy'
+ local 'GROUP=privoxy'
+ HOMEDIR=/opt/tmp/privoxy
+ CONFDIR=/opt/tmp/privoxy/conf
+ LOGDIR=/opt/tmp/privoxy/log
+ LOGFILE=/opt/tmp/privoxy/log/privoxy.log
+ PIDDIR=/opt/tmp/privoxy/run
+ PIDFILE=/opt/tmp/privoxy/run/privoxy.pid
+ '[' -d /opt/tmp/privoxy ]
+ '[' -d /opt/tmp/privoxy/conf ]
+ '[' -d /opt/tmp/privoxy/log ]
+ '[' -d /opt/tmp/privoxy/run ]
+ ARGS='--pidfile /opt/tmp/privoxy/run/privoxy.pid --user privoxy /opt/tmp/privoxy/conf/config'
+ PREARGS=
+ DESC=privoxy
+ PATH=/opt/sbin:/opt/bin
+ . /opt/etc/init.d/rc.func
+ ACTION=stop
+ CALLER=
+ ansi_red='\033[1;31m'
+ ansi_white='\033[1;37m'
+ ansi_green='\033[1;32m'
+ ansi_yellow='\033[1;33m'
+ ansi_blue='\033[1;34m'
+ ansi_bell='\007'
+ ansi_blink='\033[5m'
+ ansi_std='\033[m'
+ ansi_rev='\033[7m'
+ ansi_ul='\033[4m'
+ check
+ echo -e -n '\033[1;37m Checking privoxy... '
 Checking privoxy... + pidof privoxy
+ '[' -n 27851 ]
+ echo -e '            \033[1;32m alive. \033[m'
             alive. 
+ return 0
+ stop
+ echo -e -n '\033[1;37m Shutting down privoxy... \033[m'
 Shutting down privoxy... + killall privoxy
+ COUNTER=0
+ LIMIT=10
+ pidof privoxy
+ '[' -n  -a 0 -le 10 ]
+ pidof privoxy
+ '[' -n  ]
+ echo -e '            \033[1;32m done. \033[m'
             done. 
+ return 0
+ '[' stop '=' stop ]
+ rm -rf /opt/tmp/privoxy
~ # 
~ # 
~ # ps | grep -v grep | grep priv
~ # 

 

USER=GROUP=nobody

~ # 
~ # sed -i -e 's,^USER="privoxy",USER="nobody",' /opt/etc/init.d/S24privoxy 
~ # 
Скрытый текст
~ # 
~ # /opt/etc/init.d/S24privoxy start
+ USER=nobody
+ ENABLED=yes
+ PROCS=privoxy
+ . /opt/etc/init.d/protector
+ protect
+ local 'USER=nobody'
+ local 'GROUP=nobody'
+ HOMEDIR=/opt/tmp/privoxy
+ CONFDIR=/opt/tmp/privoxy/conf
+ LOGDIR=/opt/tmp/privoxy/log
+ LOGFILE=/opt/tmp/privoxy/log/privoxy.log
+ PIDDIR=/opt/tmp/privoxy/run
+ PIDFILE=/opt/tmp/privoxy/run/privoxy.pid
+ '[' -d /opt/tmp/privoxy ]
+ mkdir -p /opt/tmp/privoxy
+ chown nobody:nobody /opt/tmp/privoxy
+ '[' -d /opt/tmp/privoxy/conf ]
+ mkdir -p /opt/tmp/privoxy/conf
+ cp -R /opt/etc/privoxy/config /opt/etc/privoxy/config-opkg /opt/etc/privoxy/default.action /opt/etc/privoxy/default.filter /opt/etc/privoxy/match-all.action /opt/etc/privoxy/regression-tests.action /opt/etc/privoxy/templates /opt/etc/privoxy/user.action /opt/etc/privoxy/user.filter /opt/etc/privoxy/user.trust /opt/tmp/privoxy/conf/
+ chown -R nobody:nobody /opt/tmp/privoxy/conf
+ '[' -d /opt/tmp/privoxy/log ]
+ mkdir -p /opt/tmp/privoxy/log
+ touch /opt/tmp/privoxy/log/privoxy.log
+ chown -R nobody:nobody /opt/tmp/privoxy/log
+ chmod 644 /opt/tmp/privoxy/log/privoxy.log
+ '[' -d /opt/tmp/privoxy/run ]
+ mkdir -p /opt/tmp/privoxy/run
+ chown -R nobody:nobody /opt/tmp/privoxy/run
+ ARGS='--pidfile /opt/tmp/privoxy/run/privoxy.pid --user nobody /opt/tmp/privoxy/conf/config'
+ PREARGS=
+ DESC=privoxy
+ PATH=/opt/sbin:/opt/bin
+ . /opt/etc/init.d/rc.func
+ ACTION=start
+ CALLER=
+ ansi_red='\033[1;31m'
+ ansi_white='\033[1;37m'
+ ansi_green='\033[1;32m'
+ ansi_yellow='\033[1;33m'
+ ansi_blue='\033[1;34m'
+ ansi_bell='\007'
+ ansi_blink='\033[5m'
+ ansi_std='\033[m'
+ ansi_rev='\033[7m'
+ ansi_ul='\033[4m'
+ start
+ '['  '!=' yes -a  '=' cron ]
+ '[' yes '!=' yes ]
+ echo -e -n '\033[1;37m Starting privoxy... \033[m'
 Starting privoxy... + pidof privoxy
+ '[' -n  ]
+ 
+ COUNTER=0
+ LIMIT=10
+ privoxy+  --pidfilepidof privoxy
 /opt/tmp/privoxy/run/privoxy.pid --user nobody /opt/tmp/privoxy/conf/config
+ '[' -z 28028 -a 0 -le 10 ]
+ 
+ pidof privoxy
+ '[' -z '28030 28028' ]
+ echo -e '            \033[1;32m done. \033[m'
             done. 
+ logger 'Started privoxy from .'
+ return 0
+ '[' start '=' stop ]
~ # 
~ # 
~ # ps | grep -v grep | grep priv
28030 nobody    3984 S    privoxy --pidfile /opt/tmp/privoxy/run/privoxy.pid --user nobody /opt/tmp/privoxy/conf/config
~ # 
~ # /opt/etc/init.d/S24privoxy status
+ USER=nobody
+ ENABLED=yes
+ PROCS=privoxy
+ . /opt/etc/init.d/protector
+ protect
+ local 'USER=nobody'
+ local 'GROUP=nobody'
+ HOMEDIR=/opt/tmp/privoxy
+ CONFDIR=/opt/tmp/privoxy/conf
+ LOGDIR=/opt/tmp/privoxy/log
+ LOGFILE=/opt/tmp/privoxy/log/privoxy.log
+ PIDDIR=/opt/tmp/privoxy/run
+ PIDFILE=/opt/tmp/privoxy/run/privoxy.pid
+ '[' -d /opt/tmp/privoxy ]
+ '[' -d /opt/tmp/privoxy/conf ]
+ '[' -d /opt/tmp/privoxy/log ]
+ '[' -d /opt/tmp/privoxy/run ]
+ ARGS='--pidfile /opt/tmp/privoxy/run/privoxy.pid --user nobody /opt/tmp/privoxy/conf/config'
+ PREARGS=
+ DESC=privoxy
+ PATH=/opt/sbin:/opt/bin
+ . /opt/etc/init.d/rc.func
+ ACTION=status
+ CALLER=
+ ansi_red='\033[1;31m'
+ ansi_white='\033[1;37m'
+ ansi_green='\033[1;32m'
+ ansi_yellow='\033[1;33m'
+ ansi_blue='\033[1;34m'
+ ansi_bell='\007'
+ ansi_blink='\033[5m'
+ ansi_std='\033[m'
+ ansi_rev='\033[7m'
+ ansi_ul='\033[4m'
+ check
+ echo -e -n '\033[1;37m Checking privoxy... '
 Checking privoxy... + pidof privoxy
+ '[' -n 28030 ]
+ echo -e '            \033[1;32m alive. \033[m'
             alive. 
+ return 0
+ '[' status '=' stop ]
~ # 
~ # /opt/etc/init.d/S24privoxy restart
+ USER=nobody
+ ENABLED=yes
+ PROCS=privoxy
+ . /opt/etc/init.d/protector
+ protect
+ local 'USER=nobody'
+ local 'GROUP=nobody'
+ HOMEDIR=/opt/tmp/privoxy
+ CONFDIR=/opt/tmp/privoxy/conf
+ LOGDIR=/opt/tmp/privoxy/log
+ LOGFILE=/opt/tmp/privoxy/log/privoxy.log
+ PIDDIR=/opt/tmp/privoxy/run
+ PIDFILE=/opt/tmp/privoxy/run/privoxy.pid
+ '[' -d /opt/tmp/privoxy ]
+ '[' -d /opt/tmp/privoxy/conf ]
+ '[' -d /opt/tmp/privoxy/log ]
+ '[' -d /opt/tmp/privoxy/run ]
+ ARGS='--pidfile /opt/tmp/privoxy/run/privoxy.pid --user nobody /opt/tmp/privoxy/conf/config'
+ PREARGS=
+ DESC=privoxy
+ PATH=/opt/sbin:/opt/bin
+ . /opt/etc/init.d/rc.func
+ ACTION=restart
+ CALLER=
+ ansi_red='\033[1;31m'
+ ansi_white='\033[1;37m'
+ ansi_green='\033[1;32m'
+ ansi_yellow='\033[1;33m'
+ ansi_blue='\033[1;34m'
+ ansi_bell='\007'
+ ansi_blink='\033[5m'
+ ansi_std='\033[m'
+ ansi_rev='\033[7m'
+ ansi_ul='\033[4m'
+ check
+ echo -e -n '\033[1;37m Checking privoxy... '
+ pidof privoxy
+ '[' -n 28030 ]
+ echo -e '            \033[1;32m alive. \033[m'
+ return 0
+ stop
+ echo -e -n '\033[1;37m Shutting down privoxy... \033[m'
 Shutting down privoxy... + killall privoxy
+ COUNTER=0
+ LIMIT=10
+ pidof privoxy
+ '[' -n  -a 0 -le 10 ]
+ pidof privoxy
+ '[' -n  ]
+ echo -e '            \033[1;32m done. \033[m'
             done. 
+ return 0
+ start
+ '['  '!=' yes -a  '=' cron ]
+ '[' yes '!=' yes ]
+ echo -e -n '\033[1;37m Starting privoxy... \033[m'
 Starting privoxy... + pidof privoxy
+ '[' -n  ]
+ 
+ COUNTER=0
+ LIMIT=10
+ privoxy --pidfile /opt/tmp/privoxy/run/privoxy.pid --user nobody /opt/tmp/privoxy/conf/config
+ pidof privoxy
+ '[' -z 28077 -a 0 -le 10 ]
+ 
+ pidof privoxy
+ '[' -z '28079 28077' ]
+ echo -e '            \033[1;32m done. \033[m'
             done. 
+ logger 'Started privoxy from .'
+ return 0
+ '[' restart '=' stop ]
~ # 
~ # 
~ # ps | grep -v grep | grep priv
28079 nobody    3984 S    privoxy --pidfile /opt/tmp/privoxy/run/privoxy.pid --user nobody /opt/tmp/privoxy/conf/config
~ # 
~ # /opt/etc/init.d/S24privoxy stop
+ USER=nobody
+ ENABLED=yes
+ PROCS=privoxy
+ . /opt/etc/init.d/protector
+ protect
+ local 'USER=nobody'
+ local 'GROUP=nobody'
+ HOMEDIR=/opt/tmp/privoxy
+ CONFDIR=/opt/tmp/privoxy/conf
+ LOGDIR=/opt/tmp/privoxy/log
+ LOGFILE=/opt/tmp/privoxy/log/privoxy.log
+ PIDDIR=/opt/tmp/privoxy/run
+ PIDFILE=/opt/tmp/privoxy/run/privoxy.pid
+ '[' -d /opt/tmp/privoxy ]
+ '[' -d /opt/tmp/privoxy/conf ]
+ '[' -d /opt/tmp/privoxy/log ]
+ '[' -d /opt/tmp/privoxy/run ]
+ ARGS='--pidfile /opt/tmp/privoxy/run/privoxy.pid --user nobody /opt/tmp/privoxy/conf/config'
+ PREARGS=
+ DESC=privoxy
+ PATH=/opt/sbin:/opt/bin
+ . /opt/etc/init.d/rc.func
+ ACTION=stop
+ CALLER=
+ ansi_red='\033[1;31m'
+ ansi_white='\033[1;37m'
+ ansi_green='\033[1;32m'
+ ansi_yellow='\033[1;33m'
+ ansi_blue='\033[1;34m'
+ ansi_bell='\007'
+ ansi_blink='\033[5m'
+ ansi_std='\033[m'
+ ansi_rev='\033[7m'
+ ansi_ul='\033[4m'
+ check
+ echo -e -n '\033[1;37m Checking privoxy... '
 Checking privoxy... + pidof privoxy
+ '[' -n 28079 ]
+ echo -e '            \033[1;32m alive. \033[m'
             alive. 
+ return 0
+ stop
+ echo -e -n '\033[1;37m Shutting down privoxy... \033[m'
 Shutting down privoxy... + killall privoxy
+ COUNTER=0
+ LIMIT=10
+ pidof privoxy
+ '[' -n  -a 0 -le 10 ]
+ pidof privoxy
+ '[' -n  ]
+ echo -e '            \033[1;32m done. \033[m'
             done. 
+ return 0
+ '[' stop '=' stop ]
+ rm -rf /opt/tmp/privoxy
~ # 
~ # 
~ # ps | grep -v grep | grep priv
~ # 

 

USER=GROUP=www

~ # 
~ # sed -i -e 's,nobody,www,' /opt/etc/init.d/S24privoxy 
~ # 
Скрытый текст
~ # 
~ # /opt/etc/init.d/S24privoxy start
+ USER=www
+ ENABLED=yes
+ PROCS=privoxy
+ . /opt/etc/init.d/protector
+ protect
+ local 'USER=www'
+ local 'GROUP=www'
+ HOMEDIR=/opt/tmp/privoxy
+ CONFDIR=/opt/tmp/privoxy/conf
+ LOGDIR=/opt/tmp/privoxy/log
+ LOGFILE=/opt/tmp/privoxy/log/privoxy.log
+ PIDDIR=/opt/tmp/privoxy/run
+ PIDFILE=/opt/tmp/privoxy/run/privoxy.pid
+ '[' -d /opt/tmp/privoxy ]
+ mkdir -p /opt/tmp/privoxy
+ chown www:www /opt/tmp/privoxy
+ '[' -d /opt/tmp/privoxy/conf ]
+ mkdir -p /opt/tmp/privoxy/conf
+ cp -R /opt/etc/privoxy/config /opt/etc/privoxy/config-opkg /opt/etc/privoxy/default.action /opt/etc/privoxy/default.filter /opt/etc/privoxy/match-all.action /opt/etc/privoxy/regression-tests.action /opt/etc/privoxy/templates /opt/etc/privoxy/user.action /opt/etc/privoxy/user.filter /opt/etc/privoxy/user.trust /opt/tmp/privoxy/conf/
+ chown -R www:www /opt/tmp/privoxy/conf
+ '[' -d /opt/tmp/privoxy/log ]
+ mkdir -p /opt/tmp/privoxy/log
+ touch /opt/tmp/privoxy/log/privoxy.log
+ chown -R www:www /opt/tmp/privoxy/log
+ chmod 644 /opt/tmp/privoxy/log/privoxy.log
+ '[' -d /opt/tmp/privoxy/run ]
+ mkdir -p /opt/tmp/privoxy/run
+ chown -R www:www /opt/tmp/privoxy/run
+ ARGS='--pidfile /opt/tmp/privoxy/run/privoxy.pid --user www /opt/tmp/privoxy/conf/config'
+ PREARGS=
+ DESC=privoxy
+ PATH=/opt/sbin:/opt/bin
+ . /opt/etc/init.d/rc.func
+ ACTION=start
+ CALLER=
+ ansi_red='\033[1;31m'
+ ansi_white='\033[1;37m'
+ ansi_green='\033[1;32m'
+ ansi_yellow='\033[1;33m'
+ ansi_blue='\033[1;34m'
+ ansi_bell='\007'
+ ansi_blink='\033[5m'
+ ansi_std='\033[m'
+ ansi_rev='\033[7m'
+ ansi_ul='\033[4m'
+ start
+ '['  '!=' yes -a  '=' cron ]
+ '[' yes '!=' yes ]
+ echo -e -n '\033[1;37m Starting privoxy... \033[m'
 Starting privoxy... + pidof privoxy
+ '[' -n  ]
+ 
+ COUNTER=0
+ LIMIT=10
+ pidof privoxy+ privoxy --pidfile /opt/tmp/privoxy/run/privoxy.pid --user www /opt/tmp/privoxy/conf/config

+ '[' -z 28182 -a 0 -le 10 ]
+ 
+ pidof privoxy
+ '[' -z 28182 ]
+ echo -e '            \033[1;32m done. \033[m'
             done. 
+ logger 'Started privoxy from .'
+ return 0
+ '[' start '=' stop ]
~ # 
~ # ps | grep -v grep | grep priv
28185 www       3984 S    privoxy --pidfile /opt/tmp/privoxy/run/privoxy.pid --user www /opt/tmp/privoxy/conf/config
~ # 
~ # /opt/etc/init.d/S24privoxy status
+ USER=www
+ ENABLED=yes
+ PROCS=privoxy
+ . /opt/etc/init.d/protector
+ protect
+ local 'USER=www'
+ local 'GROUP=www'
+ HOMEDIR=/opt/tmp/privoxy
+ CONFDIR=/opt/tmp/privoxy/conf
+ LOGDIR=/opt/tmp/privoxy/log
+ LOGFILE=/opt/tmp/privoxy/log/privoxy.log
+ PIDDIR=/opt/tmp/privoxy/run
+ PIDFILE=/opt/tmp/privoxy/run/privoxy.pid
+ '[' -d /opt/tmp/privoxy ]
+ '[' -d /opt/tmp/privoxy/conf ]
+ '[' -d /opt/tmp/privoxy/log ]
+ '[' -d /opt/tmp/privoxy/run ]
+ ARGS='--pidfile /opt/tmp/privoxy/run/privoxy.pid --user www /opt/tmp/privoxy/conf/config'
+ PREARGS=
+ DESC=privoxy
+ PATH=/opt/sbin:/opt/bin
+ . /opt/etc/init.d/rc.func
+ ACTION=status
+ CALLER=
+ ansi_red='\033[1;31m'
+ ansi_white='\033[1;37m'
+ ansi_green='\033[1;32m'
+ ansi_yellow='\033[1;33m'
+ ansi_blue='\033[1;34m'
+ ansi_bell='\007'
+ ansi_blink='\033[5m'
+ ansi_std='\033[m'
+ ansi_rev='\033[7m'
+ ansi_ul='\033[4m'
+ check
+ echo -e -n '\033[1;37m Checking privoxy... '
 Checking privoxy... + pidof privoxy
+ '[' -n 28185 ]
+ echo -e '            \033[1;32m alive. \033[m'
             alive. 
+ return 0
+ '[' status '=' stop ]
~ # 
~ # /opt/etc/init.d/S24privoxy restart
+ USER=www
+ ENABLED=yes
+ PROCS=privoxy
+ . /opt/etc/init.d/protector
+ protect
+ local 'USER=www'
+ local 'GROUP=www'
+ HOMEDIR=/opt/tmp/privoxy
+ CONFDIR=/opt/tmp/privoxy/conf
+ LOGDIR=/opt/tmp/privoxy/log
+ LOGFILE=/opt/tmp/privoxy/log/privoxy.log
+ PIDDIR=/opt/tmp/privoxy/run
+ PIDFILE=/opt/tmp/privoxy/run/privoxy.pid
+ '[' -d /opt/tmp/privoxy ]
+ '[' -d /opt/tmp/privoxy/conf ]
+ '[' -d /opt/tmp/privoxy/log ]
+ '[' -d /opt/tmp/privoxy/run ]
+ ARGS='--pidfile /opt/tmp/privoxy/run/privoxy.pid --user www /opt/tmp/privoxy/conf/config'
+ PREARGS=
+ DESC=privoxy
+ PATH=/opt/sbin:/opt/bin
+ . /opt/etc/init.d/rc.func
+ ACTION=restart
+ CALLER=
+ ansi_red='\033[1;31m'
+ ansi_white='\033[1;37m'
+ ansi_green='\033[1;32m'
+ ansi_yellow='\033[1;33m'
+ ansi_blue='\033[1;34m'
+ ansi_bell='\007'
+ ansi_blink='\033[5m'
+ ansi_std='\033[m'
+ ansi_rev='\033[7m'
+ ansi_ul='\033[4m'
+ check
+ echo -e -n '\033[1;37m Checking privoxy... '
+ pidof privoxy
+ '[' -n 28185 ]
+ echo -e '            \033[1;32m alive. \033[m'
+ return 0
+ stop
+ echo -e -n '\033[1;37m Shutting down privoxy... \033[m'
 Shutting down privoxy... + killall privoxy
+ COUNTER=0
+ LIMIT=10
+ pidof privoxy
+ '[' -n  -a 0 -le 10 ]
+ pidof privoxy
+ '[' -n  ]
+ echo -e '            \033[1;32m done. \033[m'
             done. 
+ return 0
+ start
+ '['  '!=' yes -a  '=' cron ]
+ '[' yes '!=' yes ]
+ echo -e -n '\033[1;37m Starting privoxy... \033[m'
 Starting privoxy... + pidof privoxy
+ '[' -n  ]
+ 
+ COUNTER=0
+ LIMIT=10
+ privoxy --pidfile /opt/tmp/privoxy/run/privoxy.pid --user www /opt/tmp/privoxy/conf/config
+ pidof privoxy
+ '[' -z 28233 -a 0 -le 10 ]
+ 
+ pidof privoxy
+ '[' -z '28235 28233' ]
+ echo -e '            \033[1;32m done. \033[m'
             done. 
+ logger 'Started privoxy from .'
+ return 0
+ '[' restart '=' stop ]
~ # 
~ # 
~ # ps | grep -v grep | grep priv
28235 www       3984 S    privoxy --pidfile /opt/tmp/privoxy/run/privoxy.pid --user www /opt/tmp/privoxy/conf/config
~ # 
~ # 
~ # /opt/etc/init.d/S24privoxy stop
+ USER=www
+ ENABLED=yes
+ PROCS=privoxy
+ . /opt/etc/init.d/protector
+ protect
+ local 'USER=www'
+ local 'GROUP=www'
+ HOMEDIR=/opt/tmp/privoxy
+ CONFDIR=/opt/tmp/privoxy/conf
+ LOGDIR=/opt/tmp/privoxy/log
+ LOGFILE=/opt/tmp/privoxy/log/privoxy.log
+ PIDDIR=/opt/tmp/privoxy/run
+ PIDFILE=/opt/tmp/privoxy/run/privoxy.pid
+ '[' -d /opt/tmp/privoxy ]
+ '[' -d /opt/tmp/privoxy/conf ]
+ '[' -d /opt/tmp/privoxy/log ]
+ '[' -d /opt/tmp/privoxy/run ]
+ ARGS='--pidfile /opt/tmp/privoxy/run/privoxy.pid --user www /opt/tmp/privoxy/conf/config'
+ PREARGS=
+ DESC=privoxy
+ PATH=/opt/sbin:/opt/bin
+ . /opt/etc/init.d/rc.func
+ ACTION=stop
+ CALLER=
+ ansi_red='\033[1;31m'
+ ansi_white='\033[1;37m'
+ ansi_green='\033[1;32m'
+ ansi_yellow='\033[1;33m'
+ ansi_blue='\033[1;34m'
+ ansi_bell='\007'
+ ansi_blink='\033[5m'
+ ansi_std='\033[m'
+ ansi_rev='\033[7m'
+ ansi_ul='\033[4m'
+ check
+ echo -e -n '\033[1;37m Checking privoxy... '
 Checking privoxy... + pidof privoxy
+ '[' -n 28235 ]
+ echo -e '            \033[1;32m alive. \033[m'
             alive. 
+ return 0
+ stop
+ echo -e -n '\033[1;37m Shutting down privoxy... \033[m'
 Shutting down privoxy... + killall privoxy
+ COUNTER=0
+ LIMIT=10
+ pidof privoxy
+ '[' -n  -a 0 -le 10 ]
+ pidof privoxy
+ '[' -n  ]
+ echo -e '            \033[1;32m done. \033[m'
             done. 
+ return 0
+ '[' stop '=' stop ]
+ rm -rf /opt/tmp/privoxy
~ # 
~ # 

 

~ # 
~ # cat /opt/etc/init.d/S24privoxy 
#!/opt/bin/sh -x

USER="www"

ENABLED=yes
PROCS=privoxy

. /opt/etc/init.d/protector

ARGS="--pidfile $PIDFILE --user $USER $CONFDIR/config"
PREARGS=""
DESC=$PROCS
PATH=/opt/sbin:/opt/bin

. /opt/etc/init.d/rc.func

[ "$ACTION" = "stop" ] && rm -rf "$HOMEDIR"
~ # 
~ #
~ # 
~ # cat /opt/etc/init.d/protector 
# test protector

protect() {

local USER="$USER"
local GROUP="$USER"
HOMEDIR="/opt/tmp/$PROCS"
CONFDIR="$HOMEDIR/conf"
LOGDIR="$HOMEDIR/log"
LOGFILE="$LOGDIR/$PROCS.log"
PIDDIR="$HOMEDIR/run"
PIDFILE="$PIDDIR/$PROCS.pid"

    [ -d "$HOMEDIR" ] || {
        mkdir -p "$HOMEDIR"
        chown "$USER":"$GROUP" "$HOMEDIR"
    }

    [ -d "$CONFDIR" ] || {
        mkdir -p "$CONFDIR"
        cp -R /opt/etc/"$PROCS"/* "$CONFDIR"/
        chown -R "$USER":"$GROUP" "$CONFDIR"
    }

    [ -d "$LOGDIR" ] || {
        mkdir -p "$LOGDIR"
        touch "$LOGFILE"
        chown -R "$USER":"$GROUP" "$LOGDIR"
        chmod 644 "$LOGFILE"
    }

    [ -d "$PIDDIR" ] || {
        mkdir -p "$PIDDIR"
        chown -R "$USER":"$GROUP" "$PIDDIR"
    }
}

protect
~ # 

! не руководство к действию, а информация к размышлению !

Если предусмотрено конфигами (php-fpm, nginx, ...) или ключами (privixy, ...), этим и надо пользоваться.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...