Mailing List Archive

Apache and systemd problem
Hello all,

To learn a little bit about systemd, I recently installed a gentoo with
systemd profile.
After some fights, the OS is working, but it was a real mess !!!
Now I am struggling for launching apache2 daemon.
When apache is compiled and installed, no apache2.service appears !
It was the same problem with the mysql database...
I copied the apache2.service from Linux Mint (attached file).
systemctl enable apache2.service works but failed when starting...
(journalctl attached)

Have you any solution to resolve that issue ?

Thanks in advance.


--
Jacques
Re: Apache and systemd problem [ In reply to ]
On Wednesday, 10 May 2023 19:58:50 BST Jacques Montier wrote:
> Hello all,
>
> To learn a little bit about systemd, I recently installed a gentoo with
> systemd profile.
> After some fights, the OS is working, but it was a real mess !!!
> Now I am struggling for launching apache2 daemon.
> When apache is compiled and installed, no apache2.service appears !
> It was the same problem with the mysql database...
> I copied the apache2.service from Linux Mint (attached file).

Have you also check the necessary apache directories in /etc and /var/log/
were installed as they should and something did not go wrong with the
installation of the package?


> systemctl enable apache2.service works but failed when starting...
> (journalctl attached)
>
> Have you any solution to resolve that issue ?
>
> Thanks in advance.
>
>
> --
> Jacques

I wonder if some configuration files are missing, or the IP address/port
apache is configured to bind to is already taken by another process.

Try 'systemctl -l status apache2' and also check your '/var/logs/apache2/
error.log'.

Also run '/usr/sbin/apache2ctl configtest' and check it returns "Syntax OK",
otherwise follow any configuration errors it reports.
Re: Apache and systemd problem [ In reply to ]
Thank you Michael for your response.

- no error during compilation and installation
- /var/log/apache2 and /etc/apache2/httpd.conf are in the right place
- by default in httpd.conf:
User apache
Group apache
- User and group for /var/www -> apache:apache
- /usr/bin/apache2ctl configtest returns nothing
- when trying to start apache2.service, i get this :
apache2.service: start operation timed out. Terminating.

Cheers,

--
Jacques


Le jeu. 11 mai 2023 à 11:42, Michael <confabulate@kintzios.com> a écrit :

> On Wednesday, 10 May 2023 19:58:50 BST Jacques Montier wrote:
> > Hello all,
> >
> > To learn a little bit about systemd, I recently installed a gentoo with
> > systemd profile.
> > After some fights, the OS is working, but it was a real mess !!!
> > Now I am struggling for launching apache2 daemon.
> > When apache is compiled and installed, no apache2.service appears !
> > It was the same problem with the mysql database...
> > I copied the apache2.service from Linux Mint (attached file).
>
> Have you also check the necessary apache directories in /etc and /var/log/
> were installed as they should and something did not go wrong with the
> installation of the package?
>
>
> > systemctl enable apache2.service works but failed when starting...
> > (journalctl attached)
> >
> > Have you any solution to resolve that issue ?
> >
> > Thanks in advance.
> >
> >
> > --
> > Jacques
>
> I wonder if some configuration files are missing, or the IP address/port
> apache is configured to bind to is already taken by another process.
>
> Try 'systemctl -l status apache2' and also check your '/var/logs/apache2/
> error.log'.
>
> Also run '/usr/sbin/apache2ctl configtest' and check it returns "Syntax
> OK",
> otherwise follow any configuration errors it reports.
Re: Apache and systemd problem [ In reply to ]
On Thursday, 11 May 2023 15:07:09 BST Jacques Montier wrote:
> Thank you Michael for your response.
>
> - no error during compilation and installation

OK

> - /var/log/apache2 and /etc/apache2/httpd.conf are in the right place

Check ownership of files in /var/log/apache2/

Apache will need to be able to write to them.


> - by default in httpd.conf:
> User apache
> Group apache
> - User and group for /var/www -> apache:apache

OK

> - /usr/bin/apache2ctl configtest returns nothing

Hmm ... it should return Status OK, or 0.


> - when trying to start apache2.service, i get this :
> apache2.service: start operation timed out. Terminating.

It is missing something, can't connect to the IP/port it needs, or there's a
file missing. What is the output of:

'systemctl -l status apache2'

Also set "LogLevel info" (or debug) in its config file and restart it to see
what the apache error log reveals.
Re: Apache and systemd problem [ In reply to ]
>
> > - /var/log/apache2 and /etc/apache2/httpd.conf are in the right place
>
> Check ownership of files in /var/log/apache2/
>
> Apache will need to be able to write to them.
>
> Apache ownership of apache:apache


Inside apache2, root:root and the files are empty.

I changed the ownership of the files into apache2 to apache:apache
No change. apache2 still fails.


> > - /usr/bin/apache2ctl configtest returns nothing
>
> Hmm ... it should return Status OK, or 0.
>
> I get absolutely nothing.

>
> > - when trying to start apache2.service, i get this :
> > apache2.service: start operation timed out. Terminating.
>
> It is missing something, can't connect to the IP/port it needs, or there's
> a
> file missing. What is the output of:
>
> 'systemctl -l status apache2'
>
>
apache2.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled;
preset: disabled)
Active: failed (Result: timeout) since Thu 2023-05-11 17:46:29 CEST;
5min ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 1967 ExecStart=/usr/sbin/apache2ctl start (code=killed,
signal=TERM)
CPU: 22ms

mai 11 17:41:29 bureau systemd[1]: Starting apache2.service...
mai 11 17:46:29 bureau systemd[1]: apache2.service: start operation timed
out. Terminating.
mai 11 17:46:29 bureau systemd[1]: apache2.service: Killing process 1970
(systemctl) with signal SIGKILL.
mai 11 17:46:29 bureau systemd[1]: apache2.service: Failed with result
'timeout'.
mai 11 17:46:29 bureau systemd[1]: Failed to start apache2.service.



Also set "LogLevel info" (or debug) in its config file and restart it to
> see
> what the apache error log reveals.
>

I don't find any "LogLevel info" in /etc/apache2/httpd.conf
/var/log/apache2/error_log is empty.

Jacques
Re: Apache and systemd problem [ In reply to ]
On Thursday, 11 May 2023 17:17:27 BST Jacques Montier wrote:

> I don't find any "LogLevel info" in /etc/apache2/httpd.conf
> /var/log/apache2/error_log is empty.
>
> Jacques

Please take a look here to see what the httpd.conf should look like and if
there is no LogLevel directive add it yourself:

https://wiki.gentoo.org/wiki/Apache#.2Fetc.2Fconf.d.2Fapache2

Unfortunately I do not have access to an apache installation to compare notes,
but the above Wiki page should help with this. When troubleshooting similar
problems in the past I would run apachectl in a terminal and keep an eye in
the error.log to see what was being printed out.

The fact '/usr/bin/apache2ctl configtest' returns nothing makes me wonder if
all is well with the file /usr/bin/apache2ctl. Check:

which /usr/bin/apache2ctl
which /usr/bin/apachectl

to see which command exists in your installation.

After you are able to start it manually, you can edit your systemd service
file accordingly.
Re: Apache and systemd problem [ In reply to ]
first of all, gentoo does install with a service file:

[root@noela:~]# equery f apache | grep systemd | grep service
/lib/systemd/system/apache2.service

also, I feel the way apache works is indifferent to distro or os. i
mean, it makes very little difference as far as apache goes if you have
openrc or systemd. in the end its just a shell script to apachectl
start|stop|restart||configtest. Get a grip on logging. On how the system
logs, and how apache logs. check /etc/conf.d/apache2 which establishes
the parameters with which apache starts.


|

On 5/10/2023 9:58 PM, Jacques Montier wrote:
> Hello all,
>
> To learn a little bit about systemd, I recently installed a gentoo
> with systemd profile.
> After some fights, the OS is working, but it was a real mess !!!
> Now I am struggling for launching apache2 daemon.
> When apache is compiled and installed, no apache2.service appears !
> It was the same problem with the mysql database...
> I copied the apache2.service from Linux Mint (attached file).
> systemctl enable apache2.service works but failed when starting...
> (journalctl attached)
>
> Have you any solution to resolve that issue ?
>
> Thanks in advance.
>
>
> --
> Jacques
Re: Apache and systemd problem [ In reply to ]
Le ven. 12 mai 2023 à 02:54, Alexandru N. Barloiu <axl@dale.ro> a écrit :

> first of all, gentoo does install with a service file:
>
> [root@noela:~]# equery f apache | grep systemd | grep service
> /lib/systemd/system/apache2.service
>
> Hi Alexandru,

Gentoo did not install any apache2.service.
I had to manually edit one and those found on the net don't work.
Have you got one i could use ?

thanks in advance.

Jacques

>
>
Re: Apache and systemd problem [ In reply to ]
How can you not miss it when it's specified in the ebuild?

[root@ruja:~]# grep service
/usr/portage/www-servers/apache/apache-2.4.55-r1.ebuild
    # Then apache2.4.service can be used and systemd support controlled
    systemd_newunit "${FILESDIR}/apache2.4-hardened.service"
"apache2.service"

On 5/12/2023 11:29 AM, Jacques Montier wrote:
> /
> /
>
>
> Le ven. 12 mai 2023 à 02:54, Alexandru N. Barloiu <axl@dale.ro> a écrit :
>
> first of all, gentoo does install with a service file:
>
> [root@noela:~]# equery f apache | grep systemd | grep service
> /lib/systemd/system/apache2.service
>
> Hi Alexandru,
>
> Gentoo did not install any apache2.service.
> I had to manually edit one and those found on the net don't work.
> Have you got one i could use ?
>
> thanks in advance.
>
> Jacques
>
>>
Re: Apache and systemd problem [ In reply to ]
Le ven. 12 mai 2023 à 10:40, Alexandru N. Barloiu <axl@dale.ro> a écrit :

> How can you not miss it when it's specified in the ebuild?
>
> [root@ruja:~]# grep service
> /usr/portage/www-servers/apache/apache-2.4.55-r1.ebuild
> # Then apache2.4.service can be used and systemd support controlled
> systemd_newunit "${FILESDIR}/apache2.4-hardened.service"
> "apache2.service"
>
> I have the line in the ebuild, but no apache2.service is installed when
emerging apache.
No 00_systemd.conf in /etc/apache2/modules.d

A problem about missing uses flags ?

Here are mine

www-servers/apache-2.4.55-r1:2::gentoo USE="gdbm ssl suexec-caps systemd
-debug -doc -ldap (-selinux) (-split-usr) -static -suexec -suexec-syslog
-threads" APACHE2_MODULES="actions alias auth_basic authn_anon authn_core
authn_dbm authn_file authz_core authz_dbm authz_groupfile authz_host
authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate
dir env expires ext_filter file_cache filter headers http2 include info
log_config logio mime mime_magic negotiation rewrite setenvif socache_shmcb
speling status unique_id unixd userdir usertrack vhost_alias -access_compat
-asis -auth_digest -auth_form -authn_dbd -authn_socache -authz_dbd -brotli
-cache_disk -cache_socache -cern_meta -charset_lite -dbd -dumpio -ident
-imagemap -lbmethod_bybusyness -lbmethod_byrequests -lbmethod_bytraffic
-lbmethod_heartbeat -log_forensic (-lua) -macro -md -proxy -proxy_ajp
-proxy_balancer -proxy_connect -proxy_fcgi -proxy_ftp -proxy_hcheck
-proxy_html -proxy_http -proxy_http2 -proxy_scgi -proxy_uwsgi
-proxy_wstunnel -ratelimit -remoteip -reqtimeout -session -session_cookie
-session_crypto -session_dbd -slotmem_shm -socache_memcache -substitute
-version -watchdog -xml2enc" APACHE2_MPMS="-event -prefork -worker"
LUA_SINGLE_TARGET="lua5-1 -lua5-3 -lua5-4"

Jacques

>
>
> thanks in advance.
>
> Jacques
>
>>
>>
Re: Apache and systemd problem [ In reply to ]
>
> After you are able to start it manually, you can edit your systemd service
> file accordingly.


GOOD NEWS ! i can start apache2ctl manually by #/usr/bin/apache2ctl
I get the warning message :
AH00558: apache2: 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
But, apache2 is working as i stay localhost.

So, by editing minimal apache2.service :

[Unit]
#Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
#Documentation=https://httpd.apache.org/docs/2.4/

[Service]
#Type=forking
#Environment=APACHE_STARTED_BY_SYSTEMD=true
ExecStart=/usr/sbin/apache2ctl
ExecStop=/usr/sbin/apache2ctl graceful-stop
ExecReload=/usr/sbin/apache2ctl graceful
KillMode=mixed
#PrivateTmp=true
Restart=on-abort
TimeoutStartSec=5
[Install]
WantedBy=multi-user.target

#systemctl start apache2 works,
but #systemctl stop apache2 fails and is waiting for something....
So i can't reboot as apache2 is not stopped... :-(

Not perfect, but it is going...

--
Jacques
Re: Apache and systemd problem [ In reply to ]
On Friday, 12 May 2023 10:41:32 BST Jacques Montier wrote:
> > After you are able to start it manually, you can edit your systemd service
> > file accordingly.
>
> GOOD NEWS ! i can start apache2ctl manually by #/usr/bin/apache2ctl
> I get the warning message :
> AH00558: apache2: 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

Yes, you need to configure the apache files to specify IP address to listen
to, webroot, etc. for each host you want to serve files from.


> But, apache2 is working as i stay localhost.
>
> So, by editing minimal apache2.service :
>
> [Unit]
> #Description=The Apache HTTP Server
> After=network.target remote-fs.target nss-lookup.target
> #Documentation=https://httpd.apache.org/docs/2.4/
>
> [Service]
> #Type=forking
> #Environment=APACHE_STARTED_BY_SYSTEMD=true
> ExecStart=/usr/sbin/apache2ctl

Fix this by adding the "start" subcommand:

ExecStart=/usr/sbin/apache2ctl start
Re: Apache and systemd problem [ In reply to ]
>
> Yes, you need to configure the apache files to specify IP address to
> listen
> to, webroot, etc. for each host you want to serve files from.
>
> Ok, it's done

>
>
> Fix this by adding the "start" subcommand:
>
> ExecStart=/usr/sbin/apache2ctl start
>
>
> ExecStart=/usr/sbin/apache2ctl start does not work.

Nothing happens and system's waiting for something indefinitely ... (file
attached)

The same with ExecStart=/usr/sbin/apache2ctl stop.

So, i found a very very ugly way to make it working.

I wrote a micro bash shell script : /usr/bin/op_apache

!/bin/bash
case ${1} in
"start")
apache2ctl
;;
"stop")
#the ugly way... Don't repeat !
killall apache2
;;
esac

And i launch the script in apache2.service

#Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
#Documentation=https://httpd.apache.org/docs/2.4/

[Service]
Type=forking
ExecStart=/usr/bin/op_apache start
ExecStop=/usr/bin/op_apache stop

[Install]
WantedBy=multi-user.target

So, waiting for better, it works !

--
Jacques
Re: Apache and systemd problem [ In reply to ]
Le ven. 12 mai 2023 à 16:22, Jacques Montier <jmontier@gmail.com> a écrit :

>
>
>> Yes, you need to configure the apache files to specify IP address to
>> listen
>> to, webroot, etc. for each host you want to serve files from.
>>
>> Ok, it's done
>
>>
>>
>> Fix this by adding the "start" subcommand:
>>
>> ExecStart=/usr/sbin/apache2ctl start
>>
>>
>> ExecStart=/usr/sbin/apache2ctl start does not work.
>
> Nothing happens and system's waiting for something indefinitely ... (file
> attached)
>
> The same with ExecStart=/usr/sbin/apache2ctl stop.
>
> So, i found a very very ugly way to make it working.
>
> I wrote a micro bash shell script : /usr/bin/op_apache
>
> !/bin/bash
> case ${1} in
> "start")
> apache2ctl
> ;;
> "stop")
> #the ugly way... Don't repeat !
> killall apache2
> ;;
> esac
>
> And i launch the script in apache2.service
>
> #Description=The Apache HTTP Server
> After=network.target remote-fs.target nss-lookup.target
> #Documentation=https://httpd.apache.org/docs/2.4/
>
> [Service]
> Type=forking
> ExecStart=/usr/bin/op_apache start
> ExecStop=/usr/bin/op_apache stop
>
> [Install]
> WantedBy=multi-user.target
>
> So, waiting for better, it works !
>
> --
> Jacques
>
>


Hi Michael, Alexandru and all gentoo users,
Thanks a lot for having helped me !

Cheers !

Jacques