Changes

From Amahi Wiki
Jump to: navigation, search
Add info about starting apps on boot/reboot
To drop the same database '''<small>hda-create-db-and-user -d foo</small>'''
= Make an app start when the server (re)boots =
The best way to have your app start when the computer boots/reboots is to add an entry to the crontab. Since the install scripts are run by the user 'apache', you can only add entries to apache's crontab. This means you cannot start any apps that require root privileges.
Here is an example:
 
First use the techniques from above to create the crontab entry that starts your app/daemon/server. the line starting with @reboot is the crontab entry. at the end of the crontab entry put a comment that is unique to your app. It will be used to remove the crontab item later during uninstall.
<small>
cat > run_web-app.cron << EOF
@reboot $PWD/html/web-app.py -d # web-app
EOF
</small>
 
This made a file called web-app.cron in your apps folder. web-app.py is the program that will run as the system starts.
 
Next; the first line lists all the items in the current crontab, and copys it to a temp file. the second line add's our crontab enty to the bottom of the file. the third line loads the contents of the temp file back into the users crontab.
 
<small>
crontab -l | grep -v "no crontab for" > /tmp/crontab.txt # copy the current crontab to a tempfile
cat run_web-app.cron >> /tmp/crontab.txt #add our apps line to the tempfile
crontab /tmp/crontab.txt #make the tempfile the crontab
</small>
'''NOTE'''
The script's that manipulate the crontab needs to be carefully crafted. If not coded correctly, the users crontab will be overwritten!
 
Make sure that if you add an entry to the crontab that you have the uninstall script remove it.
Here the first line list's all enties in the crontab and grep removes any line with the string "web-app" in it. this is why it is important to use a unique identifyer at the end of your crontab line. The remaining items from the crontab go into a tempfile then the contents of the tempfile are loaded into the users crontab again.
<small>
crontab -l | grep -v web-app > /tmp/web-app-uninstall-crontab.txt
crontab /tmp/web-app-uninstall-crontab.txt
</small>
 
= Clean up =
Have fun creating your apps. If you need something ask at IRC :)
24

edits