Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug]: install script fails when option --opensourceonly is supplied #145

Closed
hannes427 opened this issue Dec 7, 2024 · 17 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@hannes427
Copy link

FreePBX Version

FreePBX 17

Issue Description

Installation fails if you supply the option --opensourceonly, because the file /var/www/html/admin/modules/sysadmin/hooks/check_ip_and_start_apache.sh could not be found. After creating the file, make it executable and rerun the installation-script the installation finished successfully

Operating Environment

Debian 12.7, latest installation script

Relevant log output

024-12-07 07:47:46 - Uninstalling sysadmin17
2024-12-07 07:47:50 - Uninstalling ioncube-loader-82
2024-12-07 07:47:51 - Wrapping up the installation process
2024-12-07 07:47:52 - Installation failed at step Wrapping up the installation process. Please check log /var/log/pbx/freepbx17-install-2024.12.07-07.37.10.log for details.
2024-12-07 07:47:52 - Error at line: 1189 exiting with code 1 (last command was: systemctl restart apache2 >> "$log")
2024-12-07 07:47:52 - Exiting script


/tmp# cat /var/log/pbx/freepbx17-install-2024.12.07-07.37.10.log
[...]
To activate the new configuration, you need to run:
  systemctl reload apache2
Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xeu apache2.service" for details.
2024-12-07 07:47:52 - ****** INSTALLATION FAILED *****
2024-12-07 07:47:52 - Installation failed at step Wrapping up the installation process. Please check log /var/log/pbx/freepbx17-install-2024.12.07-07.37.10.log for details.
2024-12-07 07:47:52 - Error at line: 1189 exiting with code 1 (last command was: systemctl restart apache2 >> "$log")
2024-12-07 07:47:52 - Exiting script

/tmp# journalctl -xeu apache2
Dez 07 07:50:50 debian-test systemd[1]: apache2.service: Scheduled restart job, restart counter is at 34.
░░ Subject: Automatic restarting of a unit has been scheduled
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ Automatic restarting of the unit apache2.service has been scheduled, as the result for
░░ the configured Restart= setting for the unit.
Dez 07 07:50:50 debian-test systemd[1]: Stopped apache2.service - The Apache HTTP Server.
░░ Subject: A stop job for unit apache2.service has finished
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ A stop job for unit apache2.service has finished.
░░ 
░░ The job identifier is 7894 and the job result is done.
Dez 07 07:50:50 debian-test systemd[1]: Starting apache2.service - The Apache HTTP Server...
░░ Subject: A start job for unit apache2.service has begun execution
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ A start job for unit apache2.service has begun execution.
░░ 
░░ The job identifier is 7894.
Dez 07 07:50:50 debian-test (pache.sh)[114926]: apache2.service: Failed to locate executable /var/www/html/admin/modules/sysadmin/hooks/check_ip_and_start_apache.sh: No such file or directory
░░ Subject: Process /var/www/html/admin/modules/sysadmin/hooks/check_ip_and_start_apache.sh could not be executed
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ The process /var/www/html/admin/modules/sysadmin/hooks/check_ip_and_start_apache.sh could not be executed and failed.
░░ 
░░ The error number returned by this process is 2.
Dez 07 07:50:50 debian-test (pache.sh)[114926]: apache2.service: Failed at step EXEC spawning /var/www/html/admin/modules/sysadmin/hooks/check_ip_and_start_apache.sh: No such file or directory
░░ Subject: Process /var/www/html/admin/modules/sysadmin/hooks/check_ip_and_start_apache.sh could not be executed
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ The process /var/www/html/admin/modules/sysadmin/hooks/check_ip_and_start_apache.sh could not be executed and failed.
░░ 
░░ The error number returned by this process is 2.
Dez 07 07:50:50 debian-test systemd[1]: apache2.service: Control process exited, code=exited, status=203/EXEC
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ An ExecStartPre= process belonging to unit apache2.service has exited.
░░ 
░░ The process' exit code is 'exited' and its exit status is 203.
Dez 07 07:50:50 debian-test systemd[1]: apache2.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ The unit apache2.service has entered the 'failed' state with result 'exit-code'.
Dez 07 07:50:50 debian-test systemd[1]: Failed to start apache2.service - The Apache HTTP Server.
░░ Subject: A start job for unit apache2.service has failed
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ A start job for unit apache2.service has finished with a failure.
░░ 
░░ The job identifier is 7894 and the job result is failed.
@hannes427 hannes427 added bug Something isn't working triage Triage labels Dec 7, 2024
@JoseGoncalves
Copy link
Contributor

JoseGoncalves commented Dec 7, 2024

This issue is not related with the install script itself but with the latest freepbx17 Debian package.

That package is installing a file named /var/www/html/admin/modules/sysadmin/hooks/update-apache-service that changes the standard apache systemd service adding to it this:

		    ExecStartPre=/var/www/html/admin/modules/sysadmin/hooks/check_ip_and_start_apache.sh

		    Restart=on-failure

		    RestartSec=5s

After doing this, it will only be possible to start/restart the apache service if the sysadmin module is installed and this should not be installed in a system with only open source modules.

P.S. Changing directly a systemd file installed by a Debian package is not a good practice. If this is really required, Sangoma should instead create an override file named /etc/systemd/system/apache2.service.d/override.conf (A Smart Way to Customize Systemd Unit Properties).

@krumble1
Copy link

For some this whole comment may be just stating the obvious, but I wanted to share this to help anyone like me who doesn't know how to undo what the freepbx17 Debian package did to apache2. Here's what I found:

Issue:

My installation ended with the following lines:

2024-12-18 15:13:32 - Installation failed at step Wrapping up the installation process. Please check log /var/log/pbx/freepbx17-install-2024.12.18-14.59.00.log for details.
2024-12-18 15:13:32 - Error at line: 1189 exiting with code 1 (last command was: systemctl restart apache2 >> "$log")
2024-12-18 15:13:32 - Exiting script

Manually systemctl restart apache2 (still as root, so no need for sudo) gave the following errors:

Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xeu apache2.service" for details.

Running systemctl status apache2.service showed, in part, the following line, which indicated that the sysadmin module had its fingers in the apache2 service somehow.

Process: 121653 ExecStartPre=/var/www/html/admin/modules/sysadmin/hooks/check_ip_and_start_apache.sh

Solution:

Lacking the knowledge of how to modify apache2 to fix this, I ran apt remove apache2 and then apt install apache2 (again, still as root, so no need to prepend with sudo). After this, running systemctl status apache2.service no longer had any mention of sysadmin in the process, so I assume this fixed the issue. Good luck, hope this helps someone!

@JoseGoncalves
Copy link
Contributor

Lacking the knowledge of how to modify apache2 to fix this, I ran apt remove apache2 and then apt install apache2 (again, still as root, so no need to prepend with sudo).

That's one way to do it. The other would be to edit file /lib/systemd/system/apache2.service, remove the lines indicated above, and execute the command sudo systemctl daemon-reload.

@kguptasangoma
Copy link
Member

Basically this file was added to ensure do not start apache until we have proper ip in place, this was required due to ioncube module in apache which was causing the issue, as this is more ioncube, added fix into sysadmin/commercial module.

	    ExecStartPre=/var/www/html/admin/modules/sysadmin/hooks/check_ip_and_start_apache.sh

I will soon try to modify the apache2 systemd file to take care of open source installation option as well. thanks.

@JoseGoncalves
Copy link
Contributor

I would sugest to add a wrapper script that checks if check_ip_and_start_apache.sh exists before trying to execute it.
That script could be something like this:

#!/bin/sh

sysadmin_script=/var/www/html/admin/modules/sysadmin/hooks/check_ip_and_start_apache.sh

if [ -x "$sysadmin_script" ]; then
    "$sysadmin_script"
fi

that you could store, for example, as /usr/bin/sysadmin_check.sh.

Then, use that wrapper script in an override file to the apache2 service, i.e., add a file named /etc/systemd/system/apache2.service.d/override.conf with:

[Service]
ExecStartPre=/usr/bin/sysadmin_check.sh

@kguptasangoma kguptasangoma removed the triage Triage label Jan 7, 2025
@kguptasangoma
Copy link
Member

just an quick update Work is in progress to fix this issue -

  1. Custom apache configuration file with below contents.

"/lib/systemd/system/apache2.service.d/freepbx_apache2_systemd_override.conf"

[Service]
ExecStartPre=/var/www/html/admin/modules/sysadmin/hooks/check_ip_and_start_apache.sh
Restart=on-failure
RestartSec=5s

  1. Install script will remove ^ custom file if using with --opensource option.

  2. this will not modify the default apache configuration.

@JoseGoncalves
Copy link
Contributor

Hi @kguptasangoma. I have some doubts that is a better option that the one I indicated previously.

What will happen if someone installs a opensource only FreePBX with the install script and then, afterwards, wants some commercial modules and installs the sysadmin module?
Will that apache systemd override file be installed as part of the installation process of the sysadmin module?
And if, after some testing, he/she want's to remove the sysadmin module
will that override file be removed?
Only if you install/remove the override file (and execute a systemctl daemon-reload) as part of the installation/removal process of the sysadmin module your sugested solution will work.

@JoseGoncalves
Copy link
Contributor

BTW, the apache systemd override file MUST be installed in this path:

  • /etc/systemd/system/apache2.service.d/override.conf.

@kguptasangoma
Copy link
Member

Will that apache systemd override file be installed as part of the installation process of the sysadmin module?

Yes sysadmin will install this file.

he/she want's to remove the sysadmin module will that override file be removed?

No as of now, it will not remove the file.

@JoseGoncalves
Copy link
Contributor

No as of now, it will not remove the file.

That needs to be done also, otherwise, restarting the apache service will crash after someone removes the sysadmin module.

@kguptasangoma
Copy link
Member

but why would someone play to install sysadmin and then uninstall it ? also installing sysadmin means ioncube , license etc needs to install.

@MSergW
Copy link

MSergW commented Jan 8, 2025

Indeed, why would someone install sysadmin and then uninstall it? This is done by the installation script, not something a person does for fun :)

sng_freepbx_debian_install.sh --opensourceonly
...
Installing FreePBX packages
Installing sysadmin17 ....
sysadmin17 installed successfully....
...
Installing FreePBX 17
Installing ioncube-loader-82 ....
ioncube-loader-82 installed successfully....
Installing freepbx17 .... (At this moment, lines are being added to the file /lib/systemd/system/apache2.service)
freepbx17 installed successfully....
Removing commercial modules
...
Uninstalling sysadmin17
Uninstalling ioncube-loader-82

Another problem:

/etc/fail2ban/jail.local
[asterisk-iptables]
...
logpath = /var/log/asterisk/fail2ban

This is incorrect.
Here need to specify /var/log/asterisk/full, or create a separate file for Asterisk to log authorization messages.

@kguptasangoma
Copy link
Member

Yea that is because we are removing commercial modules
Script will get modified to remove extra apache config.

however still during uninstall added logic to remove this extra file.

@JoseGoncalves
Copy link
Contributor

JoseGoncalves commented Jan 8, 2025

but why would someone play to install sysadmin and then uninstall it ?

I see this usage scenario. Someone installs a FreePBX 17 with the install script and the opensourceonly option.
Then he/she wants to try some commercial modules to see if they are something useful for its use case, including, for example, the sysadmin module.
After some tests with the sysadmin module he/she finds is not something useful to him and removes it. After this, a systemctl start/restart apache2 command will fail if the override file is not also removed (and systemctl daemon-reloadcalled).

Because of that, I find my solution better. With that, you could install the wrapper script sysadmin_check.sh as part of sangoma-pbx17 package and that wrapper script (that would always be installed) would call the check_ip_and_start_apache.sh script only if it exists (i.e., only if the sysadmin module is installed).

@kguptasangoma
Copy link
Member

We are removing this apache override during uninstall of sysadmin.

@JoseGoncalves
Copy link
Contributor

We are removing this apache override during uninstall of sysadmin.

OK. Don't forget to execute systemctl daemon-reload after the apache override removal, for the change to take effect immediately (otherwise, it would only be effective after a reboot).

@ramarajan222
Copy link
Contributor

Fixed with Sysadmin 17.0.2.10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants