Debugging a php's script startup

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Debugging a php's script startup

C. L. Martinez
Hi all,

 I am trying to setup a startup file for TT-Rss (installed under OpenBSD 6.2 host, fully patched). This is the script:

#!/bin/sh -x
#

daemon="/usr/local/bin/php-7.0"
daemon_flags="/var/www/htdocs/rss/update_daemon2.php --log /tmp/update_rss.log"
daemon_user="www"

. /etc/rc.d/rc.subr

pexp="${MODPHP_BIN} ${daemon}${daemon_flags:+ ${daemon_flags}}"

rc_bg=YES
rc_reload=NO

rc_post() {
        rm -f /var/www/htdocs/rss/lock/update_daemon.lock
}

rc_cmd $1

 And when I try to start it, this is the output:

root@rssweb:/etc/rc.d# ./tt_rss start
+ daemon=/usr/local/bin/php-7.0
+ daemon_flags=/var/www/htdocs/rss/update_daemon2.php --log /tmp/update_rss.log
+ daemon_user=www
+ . /etc/rc.d/rc.subr
+ _rc_actions=start stop restart reload check
+ readonly _rc_actions
+ [ -n  ]
+ basename ./tt_rss
+ _name=tt_rss
+ _rc_check_name tt_rss
+ [ -n /usr/local/bin/php-7.0 ]
+ unset _RC_DEBUG _RC_FORCE
+ getopts df c
+ shift 0
+ _RC_RUNDIR=/var/run/rc.d
+ _RC_RUNFILE=/var/run/rc.d/tt_rss
+ _rc_do _rc_parse_conf
+ eval _rcflags=${tt_rss_flags}
+ _rcflags=
+ eval _rcrtable=${tt_rss_rtable}
+ _rcrtable=
+ eval _rcuser=${tt_rss_user}
+ _rcuser=
+ eval _rctimeout=${tt_rss_timeout}
+ _rctimeout=
+ getcap -f /etc/login.conf tt_rss
+ > /dev/null
+ 2>&1
+ daemon_class=daemon
+ [ -z  ]
+ daemon_rtable=0
+ [ -z www ]
+ [ -z  ]
+ daemon_timeout=30
+ [ -n  -o start != start ]
+ [ -n  ]
+ [ -n  ]
+ [ -n  ]
+ [ -n  ]
+ [ -n  ]
+ readonly daemon_class
+ unset _rcflags _rcrtable _rcuser _rctimeout
+ pexp=/usr/local/bin/php-7.0 /var/www/htdocs/rss/update_daemon2.php --log /tmp/update_rss.log
+ rcexec=su -l -c daemon -s /bin/sh www -c
+ [ 0 -eq 0 ]
+ pexp= /usr/local/bin/php-7.0 /var/www/htdocs/rss/update_daemon2.php --log /tmp/update_rss.log
+ rc_bg=YES
+ rc_reload=NO
+ rc_cmd start
tt_rss(failed)

 pexp's option seems good ... I think the problem is with 'www' user and with this command: "su -l -c daemon -s /bin/sh www -c". Launching from console returns an error:

root@rssweb:/etc/rc.d# su -l -c daemon -s /bin/sh www -c '/usr/local/bin/php-7.0 /var/www/htdocs/rss/update_daemon2.php --log /tmp/update_rss.log'
PHP Warning:  mysqli_connect(): (HY000/2002): Can't connect to local MySQL server through socket '/var/run/mysql/mysql.sock' (2 "No such file or directory") in /var/www/htdocs/rss/classes/db/mysqli.php on line 8
Unable to connect to database (as rss to localhost, database dbrss): Can't connect to local MySQL server through socket '/var/run/mysql/mysql.sock'

 mysql's socket is created under www's chroot like in pkg-readme says: srwxrwxrwx  1 _mysql  _mysql  0 Nov  8 17:45 /var/www/var/run/mysql/mysql.sock

 If I am not wrong, then, how can I configure this startup script?

Thanks
--
Greetings,
C. L. Martinez

Reply | Threaded
Open this post in threaded view
|

Re: Debugging a php's script startup

Martijn van Duren-6
Hello C.,

Can you start up the daemon process from the CLI (without the rc
script)? If not and it still has the same error message as below (which
I reckon it will) you might want to change your mysqli.default_socket =
in your /etc/php-7.0.ini.
Do note however that this will also affect php-fpm and mod_php which run
chrooted by default (hence the weird path), so if you need those installs
unaffected try to create a custom ini-file and specify it with -c as a
php-argument.

Also note that php is not designed to write daemons in and should only
be done if there are no other options. The rc-script won't restart your
daemon automatically if it crashes.

Hope this helps.

martijn@

On 11/08/17 20:22, C. L. Martinez wrote:

> Hi all,
>
>  I am trying to setup a startup file for TT-Rss (installed under OpenBSD 6.2 host, fully patched). This is the script:
>
> #!/bin/sh -x
> #
>
> daemon="/usr/local/bin/php-7.0"
> daemon_flags="/var/www/htdocs/rss/update_daemon2.php --log /tmp/update_rss.log"
> daemon_user="www"
>
> . /etc/rc.d/rc.subr
>
> pexp="${MODPHP_BIN} ${daemon}${daemon_flags:+ ${daemon_flags}}"
>
> rc_bg=YES
> rc_reload=NO
>
> rc_post() {
>         rm -f /var/www/htdocs/rss/lock/update_daemon.lock
> }
>
> rc_cmd $1
>
>  And when I try to start it, this is the output:
>
> root@rssweb:/etc/rc.d# ./tt_rss start
> + daemon=/usr/local/bin/php-7.0
> + daemon_flags=/var/www/htdocs/rss/update_daemon2.php --log /tmp/update_rss.log
> + daemon_user=www
> + . /etc/rc.d/rc.subr
> + _rc_actions=start stop restart reload check
> + readonly _rc_actions
> + [ -n  ]
> + basename ./tt_rss
> + _name=tt_rss
> + _rc_check_name tt_rss
> + [ -n /usr/local/bin/php-7.0 ]
> + unset _RC_DEBUG _RC_FORCE
> + getopts df c
> + shift 0
> + _RC_RUNDIR=/var/run/rc.d
> + _RC_RUNFILE=/var/run/rc.d/tt_rss
> + _rc_do _rc_parse_conf
> + eval _rcflags=${tt_rss_flags}
> + _rcflags=
> + eval _rcrtable=${tt_rss_rtable}
> + _rcrtable=
> + eval _rcuser=${tt_rss_user}
> + _rcuser=
> + eval _rctimeout=${tt_rss_timeout}
> + _rctimeout=
> + getcap -f /etc/login.conf tt_rss
> + > /dev/null
> + 2>&1
> + daemon_class=daemon
> + [ -z  ]
> + daemon_rtable=0
> + [ -z www ]
> + [ -z  ]
> + daemon_timeout=30
> + [ -n  -o start != start ]
> + [ -n  ]
> + [ -n  ]
> + [ -n  ]
> + [ -n  ]
> + [ -n  ]
> + readonly daemon_class
> + unset _rcflags _rcrtable _rcuser _rctimeout
> + pexp=/usr/local/bin/php-7.0 /var/www/htdocs/rss/update_daemon2.php --log /tmp/update_rss.log
> + rcexec=su -l -c daemon -s /bin/sh www -c
> + [ 0 -eq 0 ]
> + pexp= /usr/local/bin/php-7.0 /var/www/htdocs/rss/update_daemon2.php --log /tmp/update_rss.log
> + rc_bg=YES
> + rc_reload=NO
> + rc_cmd start
> tt_rss(failed)
>
>  pexp's option seems good ... I think the problem is with 'www' user and with this command: "su -l -c daemon -s /bin/sh www -c". Launching from console returns an error:
>
> root@rssweb:/etc/rc.d# su -l -c daemon -s /bin/sh www -c '/usr/local/bin/php-7.0 /var/www/htdocs/rss/update_daemon2.php --log /tmp/update_rss.log'
> PHP Warning:  mysqli_connect(): (HY000/2002): Can't connect to local MySQL server through socket '/var/run/mysql/mysql.sock' (2 "No such file or directory") in /var/www/htdocs/rss/classes/db/mysqli.php on line 8
> Unable to connect to database (as rss to localhost, database dbrss): Can't connect to local MySQL server through socket '/var/run/mysql/mysql.sock'
>
>  mysql's socket is created under www's chroot like in pkg-readme says: srwxrwxrwx  1 _mysql  _mysql  0 Nov  8 17:45 /var/www/var/run/mysql/mysql.sock
>
>  If I am not wrong, then, how can I configure this startup script?
>
> Thanks
>

Reply | Threaded
Open this post in threaded view
|

Re: Debugging a php's script startup

C. L. Martinez
On Wed, Nov 08, 2017 at 08:43:55PM +0100, Martijn van Duren wrote:

> Hello C.,
>
> Can you start up the daemon process from the CLI (without the rc
> script)? If not and it still has the same error message as below (which
> I reckon it will) you might want to change your mysqli.default_socket =
> in your /etc/php-7.0.ini.
> Do note however that this will also affect php-fpm and mod_php which run
> chrooted by default (hence the weird path), so if you need those installs
> unaffected try to create a custom ini-file and specify it with -c as a
> php-argument.
>
> Also note that php is not designed to write daemons in and should only
> be done if there are no other options. The rc-script won't restart your
> daemon automatically if it crashes.
>
> Hope this helps.
>
> martijn@
>
> >

Wow!! ... Many many thanks Martijn. I have added "-c" switch to daemon_args and created another .ini file for this "daemon", and it works. Here it is:

#!/bin/sh -x
#

daemon="/usr/local/bin/php-7.0"
daemon_flags="-c /etc/tt-rss/php-7.0.ini /var/www/htdocs/rss/update_daemon2.php --log /tmp/update_rss.log"
daemon_user="www"

. /etc/rc.d/rc.subr

pexp="${daemon}${daemon_flags:+ ${daemon_flags}}"

rc_bg=YES
rc_reload=NO

rc_post() {
        rm -f /var/www/htdocs/rss/lock/update_daemon.lock
}

rc_cmd $1

 Inside .ini I have configured mysqli.default_socket option:

mysqli.default_socket = /var/www/var/run/mysql/mysql.sock

--
Greetings,
C. L. Martinez