Difference between revisions of "Web App Packaging Notes"
Line 9: | Line 9: | ||
mysql -uappname -pappname appname < appname.sql; | mysql -uappname -pappname appname < appname.sql; | ||
fi | fi | ||
+ | |||
+ | :or | ||
+ | |||
+ | zcat app.sql.gz |mysql -uapp -papp app | ||
'''NOTE:''' if statement switches are: | '''NOTE:''' if statement switches are: |
Revision as of 02:04, 19 February 2015
Contents
- 1 Database Restore
- 2 Database Update to UTF8
- 3 App Start on Boot
- 4 Find and Rename .htaccess Files
- 5 Add Server (Service) Feature
- 6 Custom Webapp Options
- 7 Custom .htaccess File
- 8 Special Instructions
- 9 Scripted Functions
- 10 Elevated Privileges (root)
- 11 Miscellaneous
- 12 Netboot App Template
- 13 Platform Services Feature
- 14 systemd service template
- 15 Test Checklist
Database Restore
- Install Script:
# Check for backup of old version database if [ -f /var/hda/dbs/latest-appname.bz2 ]; then # Import old version database bzcat latest-app.bz2 |mysql -uapp -papp app else # Insert new version database mysql -uappname -pappname appname < appname.sql; fi
- or
zcat app.sql.gz |mysql -uapp -papp app
NOTE: if statement switches are:
-d: directory
-f: file
Database Update to UTF8
echo "alter database appdb charset=utf8" | mysql -uappdb -pappdb
App Start on Boot
- Install Script:
/usr/bin/crontab -l > apache-crontab; cat >> apache-crontab << 'EOF' @reboot /var/hda/web-apps/appname/html/startup.sh EOF /usr/bin/crontab apache-crontab; rm -rf apache-crontab;
- Uninstall Script:
/usr/bin/crontab -l > apache-crontab; sed -i '/appname/d' apache-crontab; /usr/bin/crontab apache-crontab; rm -rf apache-crontab;
Find and Rename .htaccess Files
find . -name .htaccess -exec mv {} {}.tmp \;
Add Server (Service) Feature
- Install, Enable, and Start
Fedora:
install -m 755 appname /etc/init.d/; /sbin/chkconfig appname on; /sbin/service appname start;
Ubuntu:
install -m 755 appname /etc/init.d/; update-rc.d appname defaults; service appname start;
- Uninstall, Disable, and Stop
Fedora:
/sbin/service appname stop; /sbin/chkconfig appname off; rm -f /etc/init.d/appname;
Ubuntu:
service appname stop; update-rc.d -f appname remove; rm -f /etc/init.d/appname;
- Enable and Start (Fedora)
echo Reloading systemctl daemon; systemctl daemon-reload; echo Enabling appname service; systemctl enable appname.service; echo Starting appname service; systemctl start appname.service;
- Disable and Stop (Fedora)
echo Stopping appname service; systemctl stop appname.service; echo Disabling appname service; systemctl disable appname.service; echo Reloading systemctl daemon; systemctl daemon-reload;
- Change service run level, start, and stop priority:
Edit the service, i.e. /etc/init.d/adito and change the parameters (Run level: 0-6, start priority: 1-99, and stop priority: 1-99).
# chkconfig: 2345 56 26
Execute the following command as root user:
/sbin/chkconfig adito resetpriorities
Custom Webapp Options
Edit /etc/httpd/conf.d/####-appname.conf file (where #### is a 4 digit number). The web server will require restart to affect the changes.
- Change PHP Settings (add below ServerAlias):
<Files *.php> php_flag short_open_tag on php_flag magic_quotes_gpc Off php_flag magic_quotes_sybase Off php_flag magic_quotes_runtime Off php_flag register_globals Off php_flag session.auto_start Off php_flag suhosin.session.encrypt Off php_value upload_max_filesize 20M php_value post_max_size 100M php_value max_execution_time 300 php_value zend.enable_gc off php_value default_charset "UTF-8" php_value iconv.input_encoding "UTF-8" php_value iconv.internal_encoding "UTF-8" php_value iconv.output_encoding "UTF-8" php_value mbstring.internal_encoding UTF-8 php_value mbstring.http_output UTF-8 php_value mbstring.encoding_translation On php_value mbstring.func_overload 6 </Files>
- Apache mod_rewrite to allow use of .htaccess for Fedora 19 (replace similar lines above </Directory>):
Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted
- Apache mod_rewrite to allow use of .htaccess for older versions of Amahi (replace similar lines above </Directory>):
Options Indexes FollowSymLinks +ExecCGI AddHandler fcgid-script .fcg AllowOverride FileInfo Limit Options Indexes Order allow,deny Allow from all
- Redirect Webapp (add below ServerAlias):
ProxyPass / http://hda:10000/ ProxyPassReverse / http://hda:10000/
RedirectPermanent / http://hda:10000/
- Redirect Webapp to SSL (add below ServerAlias):
RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule (.*) https://%{HTTP_HOST}:10000 [R,L]
Custom .htaccess File
- Use of .htaccess for Webmin (requires Apache mod-rewrite step above):
RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule (.*) https://%{HTTP_HOST}:10000 [R,L]
- Some Web-Applications/Frameworks come with a pre configured .htaccess file that is trying to set the AllowOverride Rule. This will result in the following error: .htaccess: AllowOverride not allowed here. Remove AllowOverride from the .htaccess file and add it to the Directory area in your web-app conf.d file that it looks somewhat like this:
<Directory "<your path"> Options Indexes FollowSymLinks +ExecCGI AddHandler fcgid-script .fcg AllowOveride FileInfo Limit Options Indexes AllowOverride All Order allow,deny Allow from all </Directory>
Special Instructions
- Web Link Syntax:
<a href="http://www.google.com" target="_">Google</a>
- User Log in:
The administrator login is:<br /> <blockquote> <code> Name: admin<br /> Password: admin<br /> <br /> </code> </blockquote>
Scripted Functions
- Source file unarchives into unpack folder:
# Check for unpack folder if [ -d unpack ]; then rm -rf html; mv unpack html; fi
- Network Interface Name:
HDA_DEVICE=`ip route | awk '/^default/ { printf $5 }'`;
- Fully Qualified Domain Name:
HSTNM=`hostname -f` HST=`echo $HSTNM | awk -F'.' '{print $1}'` GRP=`echo $HSTNM | awk -F'.' '{print $2}'` DOM=`echo $HSTNM | awk -F'.' '{print $3}' | sed 's/\..*//'` if [$DOM == '']; then DOMNM='amahi.net' else DOMNM=$GRP'.'$DOM fi
- HDA Domain Name:
HDADOM=`cat /etc/resolv.conf | grep 'search' | awk '{ print $2 }'`;
or
HDADOM=$(echo "SELECT value FROM settings WHERE name='domain'" | mysql hda_production -uamahihda -pAmahiHDARulez -s)
- HDA IP Address
HDAIP=$(/sbin/ip -o -4 addr list $HDA_DEVICE | awk '{print $4}' | cut -d/ -f1);
- First Admin User:
FUSER=`/var/hda/platform/html/script/first-admin`
or
FUSER=$(echo "SELECT login FROM users WHERE admin=1 ORDER BY id ASC LIMIT 1" | mysql hda_production -uamahihda -pAmahiHDARulez -s)
- Arch (32- or 64-bit):
ARCH=`getconf LONG_BIT` if [ "$ARCH" = "64" ]; then # 64-bit else # 32-bit fi
- Check OS Version:
FVER=`cat /etc/fedora-release | awk -F'release ' '{print $2}' | sed 's/(Laughlin)//'`; if [ $FVER == '14' ]; then ... fi
or
FVER=`cat /etc/fedora-release | awk -F'release ' '{print $2}' | sed 's/(Verne)//'`; if [ $FVER == '16' ]; then ... fi
- Install Ubuntu (DEB) or Fedora (RPM) package
if [ -f /etc/fedora-release ]; then yum localinstall -y package.rpm --nogpgcheck fi
if [ -f /etc/lsb-release ]; then dpkg -i package.deb fi
Elevated Privileges (root)
- Scripts can be run from /var/hda/web-apps/*/elevated, /var/hda/apps/*/elevated or /var/hda/elevated directories.
mkdir -p elevated; cd elevated; cat > my-elevated-script << 'EOF' ...commands which need elevated privileges... EOF chmod +x my-elevated-script; sudo ./my-elevated-script; cd ..; rm -rf elevated;
Miscellaneous
- Suppress Console Output
command &> /dev/null
- Remove blank lines from file
sed -i '/^$/d' filename
- Delete lines in file
sed '/pattern/d' file
- Add lines before pattern
sed -i '/pattern/i \ line1 \ line2' file
- Add lines after pattern
sed -i '/pattern/a \ line1 \ line2' file
- Insert line based on text1 (Previous Line)
sed -i '/text1/ i\text2' /filename;
- Patch Comment:
# FIXME - this needs to be hosted in dl.amahi.org prior to going live!
- AmahiSync Web Link:
http://username.amahi.me/Public/filename
- Patch Diff:
diff -r -N -b -u html.orig html > app-patch.diff
patch -s -p0 -E << 'EOF' .... contents of app-patch.diff here .... 'EOF'
patch -p0 -E < app-patch.diff
- Cat EOF:
with variables
cat > test << EOF ... text goes here ... EOF
and without variables
cat > test << 'EOF' ... text goes here ... 'EOF'
- Run as First Admin User:
su $FUSER -c command
- Redirect to specific URL (change url= to desired path (i.e. http://appname/appdirectory):
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Your Page Title</title> <meta http-equiv="REFRESH" content="0;url=http://www.the-domain-you-want-to-redirect-to.com"></HEAD> <BODY> Optional page text here. </BODY> </HTML>' > html/index.html chown apache:users html/index.html
Netboot App Template
Platform Services Feature
The server list is a list of service descriptions:
- Only one service is allowed (i.e. sshd or ssh:sshd.pid).
- Once exactly one service is picked. It's the name of the service.
- Name is required, and it may be optionally followed by a PID file path
- If:
- File path doesn't start with / it's relative to /var/run/ (i.e. named:named/named.pid -> /var/run/named/named.pid)
- PID file path starts with /, then it's used as is
- No PID file path specified, then the PID file is assume to be /var/run/<name>.pid
- Does not exist, otherwise the platform will do a pgrep <name>
- Returns something, it's assumed it will be valid PIDs for that service
- Not recommended as pgrep may pick up other processes running by a name containing <name>, e.g., ssh-agent.
systemd service template
See http://blog.hqcodeshop.fi/archives/93-Handling-varrun-with-systemd.html for details.
[Service] Type=forking PrivateTmp=yes User=nobody Group=nobody # Run ExecStartPre with root-permissions PermissionsStartOnly=true ExecStartPre=-/usr/bin/mkdir -p /var/run/dhis ExecStartPre=/usr/bin/chown -R nobody:nobody /var/run/dhis/ # Run ExecStart with User=nobody / Group=nobody ExecStart=/usr/sbin/dhid -P /var/run/dhis/dhid.pid PIDFile=/var/run/dhis/dhid.pid
Test Checklist
Amahi Greyhole
1. Install Greyhole and verify no errors
rpm -Uvh URL
2. Check the Greyhole log for normal behavior
tail -f /var/log/greyhole.log
3. Stop, start, and restart the service, checking status for errors
systemctl stop amahi-greyhole.service systemctl status amahi-greyhole.service systemctl start amahi-greyhole.service systemctl status amahi-greyhole.service systemctl restart amahi-greyhole.service systemctl status amahi-greyhole.service
4. Add a few files to Greyhole-enabled shares and check log for errors
tail -f /var/log/greyhole.log
5. At command line, execute the following which should yield 1 line with 3 numbers
greyhole-dfree
6. Verify in dashboard that Disk Partitions appear correctly
7. Reboot machine to ensure Greyhole starts without errors
ps guax | grep greyhole tail -f /var/log/greyhole.log
8. Verify version of amahi-greyhole installed is correct
greyhole
9. Delete 1 file and check log for activity
tail -f /var/log/greyhole.log
10. Force greyhole to manage files and check log for errors
greyhole -f tail -f /var/log/greyhole.log
11. Empty the attic and it should reflect something being removed.
greyhole -a
12. Check log to verify still working correctly and should show sleeping.
tail -f /var/log/greyhole.log
If any of the steps are not correct, there is most likely a bug. This testing must be on an Amahi 7 machine with the latest Amahi platform and no OS updates installed. Basically it should appear like a new install.
Amahi Platform
Things to test in new platform releases:
- users
- creation
- deletion
- adding public key
- make user admin
- make sure admin cannot remove self from being admin
- shares area
- create a share, delete it
- set all permissions, test them (at the very least visually in /etc/samba/smb.conf)
- disks area
- shows right disks and partitions
- apps installation
- with server
- with share
- with database
- theme
- plugin-based apps
- network settings
- create alias
- create static IP
- go to settings, verify that you can change the DNS provider, including custom # # settings
- in settings, verify that the lease time can be changed
- in settings, verify (quickly) that you can change the gateway
- settings area
- make sure the language can be changed
- make sure advanced settings work and other things show up in other tabs (e.g. shares -- suggest you open that one in a separate tab and refresh)
- make sure it's possible to restart the server and power it off
- make sure guest dashboard is accessible when the option is checked
- go to the themes subtab and change themes
- go to the servers area, and see if you can stop, restart, unmonitor and otherwise permanently stop a harmless server (not a critical server like hda-ctl, mysql, apache, etc.).