termux-packages icon indicating copy to clipboard operation
termux-packages copied to clipboard

Corrupted httpd.pid file causes 'apachectl stop' to fail

Open tigran123 opened this issue 8 years ago • 7 comments

On my nexus10 I tried to stop apache2 server and got this:

$ ps -ef | grep httpd
u0_a79    8944     1  0 Oct22 ?        00:00:01 /data/data/com.termux/files/usr/bin/httpd -k start
u0_a79    8947  8944  0 Oct22 ?        00:00:02 /data/data/com.termux/files/usr/bin/httpd -k start
u0_a79    8955  8944  0 Oct22 ?        00:00:00 /data/data/com.termux/files/usr/bin/httpd -k start
u0_a79    8973  8944  0 Oct22 ?        00:00:02 /data/data/com.termux/files/usr/bin/httpd -k start
u0_a79    9102  8944  0 Oct22 ?        00:00:01 /data/data/com.termux/files/usr/bin/httpd -k start
u0_a79   28896 28878  0 13:09 pts/1    00:00:00 grep httpd
$ pwd
/data/data/com.termux/files/usr/var/run/apache2
$ cat httpd.pid 
-5267968690682322192
$ apachectl stop
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
(20014)Internal error (specific information not available): AH00058: Error retrieving pid file var/run/apache2/httpd.pid
AH00059: Remove it before continuing if it is corrupted.

If I remove this file, then manually pkill httpd and then start apache2 again via apachectl start the httpd.pid file contains garbage again:

$ cat httpd.pid 
-5267317779798658823

But note that this is a different garbage than before. So, my guess is that (since the pid of httpd master process is different now) the pid is corrupted (like unsigned <-> signed long issues) when storing it in the file.

I'll check now what happens in aarch64 architecture (on LG G4) and report here.

tigran123 avatar Oct 28 '17 12:10 tigran123

On aarch64 architecture everything is fine, i.e. the correct pid is stored and apachectl start/stop works as expected.

tigran123 avatar Oct 28 '17 12:10 tigran123

A work around about this is https://gist.github.com/yoander/a7fd18c05475a1f04253b9f74db3c96b

yoander avatar Aug 18 '18 15:08 yoander

Possibly bug in the termux apache build script?

	if [ $TERMUX_ARCH_BITS -eq 32 ]; then
		export ap_cv_void_ptr_lt_long=4
	else
		export ap_cv_void_ptr_lt_long=8
fi

ap_cv_void_ptr_lt_long is "yes" or "no" option.

from acinclude.m4 in apache

AC_DEFUN([APACHE_CHECK_VOID_PTR_LEN], [

AC_CACHE_CHECK([for void pointer length], [ap_cv_void_ptr_lt_long],
[AC_TRY_RUN([
int main(void)
{
    return sizeof(void *) < sizeof(long); 
}], [ap_cv_void_ptr_lt_long=no], [ap_cv_void_ptr_lt_long=yes], 
    [ap_cv_void_ptr_lt_long="cross compile - not checked"])])

if test "$ap_cv_void_ptr_lt_long" = "yes"; then
    AC_MSG_ERROR([Size of "void *" is less than size of "long"])
fi
])

gauravdash avatar Dec 31 '18 13:12 gauravdash

$:apachectl stop $:(20014)Internal error (specific information not available): AH00058: Error retrieving pid file var/run/apache2/httpd.pid AH00059: Remove it before continuing if it is corrupted.

When ever I start apache2 by writing $:apachectl start server starts and work with any error but when ever I am stop the server by writing $:apachectl stop issue arises . . May be temporary solution is that you can start the server normally and stop it by closing and removing termux from ram and then if you want to start it again you have to remove or delete this file that is located at var/run/apache2/httpd.pid Go to this file location and delete https.pid by writing $:rm https.pid . . After removing this file you may run apache by writing $:apachectl start and repeat these steps if it's work for you

ripgamer avatar Aug 14 '20 04:08 ripgamer

This issue/PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 18 '21 18:11 stale[bot]

Sorry, I forgot to close this issue. Better late, than never :)

tigran123 avatar Nov 18 '21 19:11 tigran123

Create and run stopapache.sh

#!/usr/bin/env bash
pidf=$(ps ax -o pid=,args= | grep httpd | grep -v 'grep' | head -n1 | grep -o -P '(\d{3,5})')
until [[ -z $pidf ]] ; do
	kill -9 $pidf 2> /dev/null
	pidf=$(ps ax -o pid=,args= | grep httpd | grep -v 'grep' | head -n1 | grep -o -P '(\d{3,5})')
done
#apache2 on Termux. Comment if use proot:
pidf=$PREFIX/var/run/apache2/httpd.pid
#For proot uncomment this:
#pidf=/var/run/apache2/httpd.pid
[[ -f $pidf ]] && rm -f $pidf

Edit theses lines on Termux:

nano /data/data/com.termux/files/usr/etc/apache2/httpd.conf
Listen 8080
ServerName localhost

On proot file may be is:

nano /etc/apache2/apache2.conf
or
nano /etc/apache2/httpd.conf

Start server: apachectl start On browser access 127.0.0.1:8080 Stop server: bash stopapache.sh

sharesourcecode avatar Dec 06 '21 14:12 sharesourcecode

Is this still an issue? I cannot reproduce on Android 11 arm...

truboxl avatar Apr 10 '23 07:04 truboxl

Reopen was my operation mistake. Rationale: I reopened issues that were closed by Stale bot, which is not the case with this specific issue, obviously.

xtkoba avatar Apr 10 '23 17:04 xtkoba