If anyone from Schmooze.com is reading this, how do you feel about a script that uses the concepts of the two lines below plus logging the output being posted as a module update script?
Most of the rest of the script is not necessary other than corner case situations like for new language translations to take affect which would need apache restarted.
But … speaking of that script, if I am not mistaken, that script is copyrighted to Schmooze. If you are going to post it here, I think you should probably do a couple things. First, probably check with Schmooze if that is ok. Second, keep their copyright with the script you are posting.
As a general rule, putting something like this here will usually result in more bad then good. The standard commands that I listed are maintained by FreePBX and are kept up-to-date. What is in scripts that come on a distro tend to me a lot more fragile.
You’ll also run into problems sometimes if you do the above with modules like the sysadmin module which may require up-to-date RPMs to also be installed and the upgrades you listed above do none of that where as the Distro scripts would make sure to pull any necessary RPMs as part of that particular upgrade.
Anyhow … for now, can you go back and at least add any Copyright that you may have found with that script and it would probably be courteous to check with Schmooze if they are ok leaving it up. Thanks! and thanks for trying to help others!
You’ll also run into problems sometimes if you do the above with modules like the sysadmin module which may require up-to-date RPMs to also be installed and the upgrades you listed above do none of that where as the Distro scripts would make sure to pull any necessary RPMs as part of that particular upgrade.
Thanks for mentioning that as a possible dependency.
Would the same dependency breakage occur if someone where to update FreePBX modules through the normal Module Admin web page? I’m trying just to automate that module update process, assuming that is safe to do.
As the distro update script is much more invasive (Asterisk core updates, OS package updates, etc.), I would think that would always be done by hand by the admin.
I have no issues with that but based on what Philippe had stated in the original post you can use what we do as it handles a few errors we saw in the past we just ask that our copyright stay in place.
EDIT: SEE THE BOTTOM OF THIS THREAD FOR THE BEST VERSION OF THIS SCRIPT
Thank you for that generosity, Tony!
Based on these two statements below, I wasn’t sure if the right approach was to keep the extra commands in the script (chown, restart Apache, etc.) or just call “module_admin upgradeall” followed by “module_admin reload” and not the other commands.
Philippe mentioned:
The standard commands that I listed are maintained by FreePBX and are kept up-to-date. What is in scripts that come on a distro tend to me a lot more fragile.
Tony mentioned:
but based on what Philippe had stated in the original post you can use what we do as it handles a few errors we saw in the past
Here is a revised script to have something concrete to see:
...
EDIT: SEE THE BOTTOM OF THIS THREAD FOR THE BEST VERSION OF THIS SCRIPT
...
I was curious about your experience because this script has been working fine for me through crond. I checked /etc/sudoers on two FreePBX Distro 2.10 servers and found that the default configuration there was to have this line commented out entirely:
...
Disable "ssh hostname sudo ", because it will show the password in clear.
You have to run "ssh -t hostname sudo ".
#Defaults requiretty
…
In the above configuration, the module update script works OK through crond.
Both these servers are FreePBX Distro 2.10-based installs, and were that way from the start of their life (that is, not upgraded from FreePBX Distro 2.9).
Are you maybe using a different base distribution, or a different version of FreePBX Distro?
set our permissions to avoid disaster, or at the very least breaking things
which amportal chown > /dev/null
###########################################################################
end update check
echo “date: FreePBX module update check completed. See above for any module installation messages. If no ‘Module … successfully installed’ messages are displayed, no modules were found that needed updating.” >> “$logfile”
make the script executable
chmod +x /usr/local/bin/update_freepbx_modules.sh
==== Manually run the upgrade script to test it ====
su -
/usr/local/bin/update_freepbx_modules.sh
if any modules are updated, a status update line will display to the console, otherwise nothing will display to the console
sample expected log file output with some modules updated
cat /var/log/pbx/upgrade/*moduleupdates*
Sun Apr 29 19:11:16 EDT 2012: FreePBX module update check starting...
Module conferences successfully installed
Sun Apr 29 19:11:19 EDT 2012: FreePBX module update check completed. See above for any module installation messages. If no 'Module ... successfully installed' messages are displayed, no modules were found that needed updating.
==== Create a cron job to automatically run the upgrade script ====
Ensure the local root user has e-mail forwarded to a monitored e-mail address
vi /etc/cron.d/update_freepbx_modules
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
MAILTO=root
HOME=/
Minute Hour Day of Month Month Day of Week User Command
apply FreePBX module updates every morning at the desired time (1:00 AM in the example below)
I had an issue running this script on freepbx distro. It worked when executed manually, but not from cron.
After some digging, I found the following in /var/log/secure:
Jun 5 01:00:01 freepbx sudo: root : sorry, you must have a tty to run sudo ;
TTY=unknown ; PWD=/ ; USER=asterisk ; COMMAND=/var/lib/asterisk/bin/module_admin
upgradeall
It turns out that sudo has the “requiretty” flag enabled by default in this distro. My solution was to disable this flag for root:
Run ‘visudo’ and add the following line below “Defaults requiretty”:
The script hangs when I run it. This is the log from /var/log/secure:
Jul 13 00:59:28 sshd[28542]: Accepted password for root from <redacted> port <redacted> ssh2
Jul 13 00:59:28 sshd[28542]: pam_unix(sshd:session): session opened for user root by (uid=0)
Jul 13 00:59:28 sshd[28546]: lastlog_filetype: Couldn't stat /var/log/lastlog: No such file or directory
Jul 13 00:59:28 sshd[28546]: lastlog_openseek: /var/log/lastlog is not a file or directory!
Jul 13 00:59:28 sshd[28546]: lastlog_filetype: Couldn't stat /var/log/lastlog: No such file or directory
Jul 13 00:59:28 sshd[28546]: lastlog_openseek: /var/log/lastlog is not a file or directory!
Jul 13 01:02:53 sshd[28634]: Did not receive identification string from UNKNOWN
Jul 13 01:03:23 sshd[28672]: Did not receive identification string from UNKNOWN
Jul 13 01:06:20 su: pam_unix(su-l:session): session opened for user root by root(uid=0)
Jul 13 01:11:02 sudo: root : TTY=pts/0 ; PWD=/root ; USER=asterisk ; COMMAND=/var/lib/asterisk/bin/module_admin upgradeall
Jul 13 01:11:04 sudo: root : TTY=pts/0 ; PWD=/root ; USER=asterisk ; COMMAND=/var/lib/asterisk/bin/module_admin reload
Jul 13 01:11:44 sshd[28831]: Did not receive identification string from UNKNOWN
Jul 13 01:12:04 sshd[28859]: Did not receive identification string from UNKNOWN
Jul 13 01:12:34 sshd[28900]: Did not receive identification string from UNKNOWN
Jul 13 01:13:05 sshd[28939]: Did not receive identification string from UNKNOWN
Jul 13 01:13:35 sshd[28977]: Did not receive identification string from UNKNOWN
Jul 13 01:14:05 sshd[29015]: Did not receive identification string from UNKNOWN
Jul 13 01:14:35 sshd[29052]: Did not receive identification string from UNKNOWN
Jul 13 01:15:06 sshd[29091]: Did not receive identification string from UNKNOWN
Jul 13 01:15:36 sshd[29128]: Did not receive identification string from UNKNOWN
Jul 13 01:16:06 sshd[29169]: Did not receive identification string from UNKNOWN
Jul 13 01:16:37 sshd[29220]: Did not receive identification string from UNKNOWN
Jul 13 01:17:08 sshd[29260]: Did not receive identification string from UNKNOWN
Jul 13 01:17:38 sshd[29300]: Did not receive identification string from UNKNOWN
Jul 13 01:17:45 sudo: root : TTY=pts/0 ; PWD=/usr/local/bin ; USER=asterisk ; COMMAND=/var/lib/asterisk/bin/module_admin upgradeall
Jul 13 01:17:47 sudo: root : TTY=pts/0 ; PWD=/usr/local/bin ; USER=asterisk ; COMMAND=/var/lib/asterisk/bin/module_admin reload
Jul 13 01:18:18 sshd[29406]: Did not receive identification string from UNKNOWN
Jul 13 01:19:14 sshd[29418]: Did not receive identification string from UNKNOWN
Jul 13 01:19:44 sshd[29463]: Did not receive identification string from UNKNOWN
Jul 13 01:20:14 sshd[29504]: Did not receive identification string from UNKNOWN
Jul 13 01:20:44 sshd[29541]: Did not receive identification string from UNKNOWN
Jul 13 01:21:15 sshd[29581]: Did not receive identification string from UNKNOWN
Jul 13 01:21:34 sudo: root : TTY=pts/0 ; PWD=/usr/local/bin ; USER=asterisk ; COMMAND=/var/lib/asterisk/bin/module_admin upgradeall
Jul 13 01:21:35 sudo: root : TTY=pts/0 ; PWD=/usr/local/bin ; USER=asterisk ; COMMAND=/var/lib/asterisk/bin/module_admin reload
Jul 13 01:21:45 sshd[29708]: Did not receive identification string from UNKNOWN
Jul 13 01:22:15 sshd[29747]: Did not receive identification string from UNKNOWN
Jul 13 01:22:42 sudo: root : TTY=pts/0 ; PWD=/usr/local/bin ; USER=asterisk ; COMMAND=/var/lib/asterisk/bin/module_admin upgradeall
Jul 13 01:22:43 sudo: root : TTY=pts/0 ; PWD=/usr/local/bin ; USER=asterisk ; COMMAND=/var/lib/asterisk/bin/module_admin reload
Jul 13 01:22:51 sshd[29874]: Did not receive identification string from UNKNOWN
Jul 13 01:23:26 sshd[29883]: Did not receive identification string from UNKNOWN
Jul 13 01:23:56 sshd[29922]: Did not receive identification string from UNKNOWN
Jul 13 01:24:27 sshd[29959]: Did not receive identification string from UNKNOWN
Jul 13 01:24:57 sshd[29998]: Did not receive identification string from UNKNOWN
Jul 13 01:25:27 sshd[30035]: Did not receive identification string from UNKNOWN
Jul 13 01:25:58 sshd[30072]: Did not receive identification string from UNKNOWN
Jul 13 01:26:28 sshd[30111]: Did not receive identification string from UNKNOWN
I’m not a linux guy. Any idea how to fix this problem?