WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: PPI question-where does what file go in original apps.  (Read 4185 times)

Offline softwaregurl

  • Suspended
  • Full Member
  • ***
  • Posts: 109
PPI question-where does what file go in original apps.
« on: April 30, 2009, 04:00:40 AM »
Let's take a hypothetical case of an original application.  Some written in C, some sh, some Perl (maybe compiled with the backend compiler).  Interfaces include command line, web based, JWM tray and normal gui's.

this is what I get so far:

    1) Everything needs to be in /usr/local/
    2) Data that needs to persist reboots should be in /home/$USER/.program_name/
    3) Binaries go in /usr/local/bin
    4) bash and scripts go in /usr/local/sbin
    5) libraries go in /usr/local/lib
    6) the setup script then copies things elsewhere such as default config files and creates symlinks as needed after testing if their already there as well as what ever else one wishes.

Is that right so far?
The questions and scenarios:
    1) Does it matter if something is in /usr/local/bin or /usr/local/program_name/bin if it doesn't need to be in the path?
        a) I'm guessing anything that needs to be found can be symlinked to or added to the path.  Which is better?
    2) Default config files and other dynamic files can reside in /usr/local/program_name/skel/ then copy to /home/$USER/.program_name/ so this brings the question does the setup script run on every boot in every mode and will it always do so? eg: is everything in /usr/local/tce.installed executed even with persistent local and extensions not reloaded?
       a) Does the setup script run as root, user tc or $USER? Is there a difference between boot, installing from the repository or loading optional?
       b) Does or will it hurt anything to sudo things if it's run as root?
       c) on boot the setup script runs long before X starts I guess.  Is there an easy way to tell when X has started and do stuff afterwords?  Maybe a loop that exits when a file exists and sleep between tests to cut cpu usage.
       d) on boot does the setup script run before or after /etc/skel is copied?
    3)  Executables that are called from web pages and static web pages would normally be within the website.  There is no good reason I can see for them to be in the backup.
        a)Should they maybe be in /usr/local/program_name/www/..... then symlinked such as /home/$USER/htdocs/directory --> /home/$USER/.program_name/www then /home/$USER/.program_name/www/cgi-bin --> /usr/local/program_name/www/cgi-bin etc... or will that cause problems?
        b) can the symlinks all be prefab in /usr/local/program_name/skel/.program_name/www/..... or do they need to be created by the script?  Will they persist in the backup?
    4) What really is a lib?  Closest I can figure is it is like a require or include in Perl.  When should something go in  /usr/local/lib?
    5) Where is the best place for log files?  They can get excessive in size for persistence.
    6) Should Perl scripts to be called from the command line go in /usr/local/sbin?
edit: 7) Does a list of auto scanned extensions exist somewhere to see what else is being loaded?  It might be handy for Apache2 to auto configure if, say, apache2-docs, Perl, Php, etc... is also being loaded on boot.

A lot of what I ask is what may work today but become a big gotcha in the future.
Thanks Jason W for the tips so far.
« Last Edit: April 30, 2009, 04:40:43 AM by softwaregurl »
Old wounds that have never healed need to be re-exposed before the cure can be applied.  The cure must be available before the wound is re-exposed.

Offline mikshaw

  • Sr. Member
  • ****
  • Posts: 368
Re: PPI question-where does what file go in original apps.
« Reply #1 on: April 30, 2009, 09:19:02 AM »
Quote
4) bash and scripts go in /usr/local/sbin
The sbin directories are for administrative tools.  The scripts should probably also go in /usr/local/bin

Quote
1) Does it matter if something is in /usr/local/bin or /usr/local/program_name/bin if it doesn't need to be in the path?
If they don't need to be in PATH, then it doesn't matter.
Quote
a) I'm guessing anything that needs to be found can be symlinked to or added to the path.  Which is better?
I'd say it depends on how many files you have.  If it's just one or two a symlink would be better, although it might still be better to install those files into /usr/local/bin unless that will cause trouble (hard-linked paths in the main executable, for example).  If you have adirectory filled with piles of executables, adding that directory to PATH seems like it would be a lot more convenient.

Quote
2) Default config files and other dynamic files can reside in /usr/local/program_name/skel/ then copy to /home/$USER/.program_name/ so this brings the question does the setup script run on every boot in every mode and will it always do so? eg: is everything in /usr/local/tce.installed executed even with persistent local and extensions not reloaded?
If it's in the /usr/local/tce.installed directory then yes, unless it makes itself non-executable after running (i'm not sure about every mode).  I'm curious to know where this script is copying the files...if they go into /home/tc then they won't be available for other users.  What I've done in the past is make a wrapper script for the application to take the place of the application itself.  The script checks for the needed configuration file or directory, and creates it if it doesn't exist.  It then executes the application.

Quote
c) on boot the setup script runs long before X starts I guess.  Is there an easy way to tell when X has started and do stuff afterwords?
The most common way to do this is add commands to $HOME/.xsession.

Quote
d) on boot does the setup script run before or after /etc/skel is copied?
After.  It's one of the very last things done.

I'm not following number 3 very well, so can't respond to it yet.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: PPI question-where does what file go in original apps.
« Reply #2 on: April 30, 2009, 10:34:29 AM »
Extension install scripts are always run as root, no matter whether loaded on boot, manually, from appbrowser etc.

Using sudo as root is ok; the default rules allow root to get root without a password ;)
The only barriers that can stop you are the ones you create yourself.

Offline softwaregurl

  • Suspended
  • Full Member
  • ***
  • Posts: 109
Re: PPI question-where does what file go in original apps.
« Reply #3 on: April 30, 2009, 02:33:25 PM »
LOL@curaga
Quote
the default rules allow root to get root without a password Wink
The only barriers that can stop you are the ones you create yourself.
So root can be it's self without asking it's self permission! Or, root is not creating barriers that can stop it's self!

@mikshaw: Thanks for the correction on sbin.
Quote
I'm not following number 3 very well, so can't respond to it yet.
I will try to explain better.  A web site may have pages created by a script eg: example.cgi gets called by index.html and creates/updates example.html.  example.html needs to be in the backup because it changes.  example.cgi and index.html better not be changing so would be a waste to backup but need to be within the web site.
Apache2 (until updated) looks for the site in /home/tc/htdocs.  It would be easier to have this part of the site all in one place but the site in its default place, thus the symlink scenarios.  A completely botched configuration could be wiped and start from scratch by removing one directory.

The rest looks good but it will take a little time for my cranial emulator to fully process it.
Thanks all again.
Old wounds that have never healed need to be re-exposed before the cure can be applied.  The cure must be available before the wound is re-exposed.

Offline mikshaw

  • Sr. Member
  • ****
  • Posts: 368
Re: PPI question-where does what file go in original apps.
« Reply #4 on: April 30, 2009, 04:09:41 PM »
I see...you have a website, or part of the website, in the user's directory.  I've never had any experience with that.  I suppose symlinks will work.  One problem that might happen is if you've configured the server to chroot, although I have no experience with that either...it might still work.  The symlinks should persist in a backup.

Quote
4) What really is a lib?  Closest I can figure is it is like a require or include in Perl.  When should something go in  /usr/local/lib?
That's close enough an explanation as far as I'm concerned.  Libraries are merely code that can be shared by multiple applications, allowing you to make smaller apps and save you from having to rewrite what has already been written.  A dynamic library is typically put in one of the "lib" directories because those directories are listed in ld.so.conf.  This is the equivalent of how $PATH works for executables.  If your libraries are for Perl this probably doesn't apply....I think they should be put in a directory specific to Perl.

Quote
5) Where is the best place for log files?  They can get excessive in size for persistence.
/var/log, or a subdirectory of /var/log, is the typical place, but I think it depends on what works for you.  If you create them in $HOME somewhere, you can add them to .xfiletool.lst to keep them out of your backup.

Quote
6) Should Perl scripts to be called from the command line go in /usr/local/sbin?
Probably not.  This goes back to the point about sbin being for system admin, not for users.

Quote
7) Does a list of auto scanned extensions exist somewhere to see what else is being loaded?  It might be handy for Apache2 to auto configure if, say, apache2-docs, Perl, Php, etc... is also being loaded on boot.
/usr/local/tce.installed should show you all the extensions that have been installed.   If you check that directory for a specific extension (minus the ".tce"), you can have apache do whatever you need to do if the extension is listed there.  The extension install scripts are run after all extensions have loaded, so you won't have to be concerned that the scripts run alphabetically.

Offline softwaregurl

  • Suspended
  • Full Member
  • ***
  • Posts: 109
Re: PPI question-where does what file go in original apps.
« Reply #5 on: May 22, 2009, 02:04:49 PM »
Quote
#copy some files if not there
if [ ! -f "$HOME"/.mediaswg ]; then
 cp -r /usr/local/mediaswg/skel/.mediaswg "$HOME"/
fi
This works fine loading optional, but on boot it puts the files in /.mediaswg so $HOME must not be set yet.  same problem with using sed on .jwmrc-tray (it creates /.jwmrc-tray).  Is $USER set yet or a way to tell where home is?

using tinycore_1.3 and 1.2
Old wounds that have never healed need to be re-exposed before the cure can be applied.  The cure must be available before the wound is re-exposed.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: PPI question-where does what file go in original apps.
« Reply #6 on: May 22, 2009, 03:46:40 PM »
I see the issue. A fix would be to add
Quote
export HOME=/home/"$USER"
at line 277 in tc-config (right after the line "mkdir -p /home/"$USER"")

edit: this location is for tc2
« Last Edit: May 22, 2009, 03:51:43 PM by curaga »
The only barriers that can stop you are the ones you create yourself.

Offline roberts

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: PPI question-where does what file go in original apps.
« Reply #7 on: May 22, 2009, 04:27:06 PM »
No user is logged in during booting. So / is normal during the boot process.
I have always used /home/"$USER" based on the default stored in /etc/sysconfig/tcuser.
« Last Edit: May 22, 2009, 10:03:51 PM by roberts »
10+ Years Contributing to Linux Open Source Projects.

Offline jls

  • Hero Member
  • *****
  • Posts: 2135
Re: PPI question-where does what file go in original apps.
« Reply #8 on: May 22, 2009, 05:21:07 PM »
this is the explanation of the Filesystem Hierarchy Standard:
http://www.pathname.com/fhs/pub/fhs-2.3.html
dCore user

Offline mikshaw

  • Sr. Member
  • ****
  • Posts: 368
Re: PPI question-where does what file go in original apps.
« Reply #9 on: May 23, 2009, 08:06:35 AM »
Quote from: softwaregurl
on boot it puts the files in /.mediaswg so $HOME must not be set yet.  same problem with using sed on .jwmrc-tray (it creates /.jwmrc-tray).  Is $USER set yet or a way to tell where home is?
Quote from: roberts
No user is logged in during booting. So / is normal during the boot process.
Depending on how the application itself is run, I think it might not be the most reliable method to copy files to one specific user's during boot.  What happens if a different user logs in and tries to use the application...the mediaswg files don't exist for that user.
Also remember to chown files that are copied to an arbitrary user's directory.

Offline softwaregurl

  • Suspended
  • Full Member
  • ***
  • Posts: 109
Re: PPI question-where does what file go in original apps.
« Reply #10 on: June 06, 2009, 11:07:38 AM »
I have posted more details of the problems on my own forum because it is lengthy and more to do with my own projects then TCL. Feel free to copy and paste anything back here that you would like.
I just started http://softwaregurl.com/forum/index.php/topic,7.0.html with details.
Old wounds that have never healed need to be re-exposed before the cure can be applied.  The cure must be available before the wound is re-exposed.

Offline mikshaw

  • Sr. Member
  • ****
  • Posts: 368
Re: PPI question-where does what file go in original apps.
« Reply #11 on: June 07, 2009, 10:24:02 AM »
I know naught about fifo, so I probably can't help with your problem.  I can, however, be an annoyance by suggesting some code cleanup =o)

Quote from: softwaregurl
[ -f /tmp/.mediaswg ] || mkdir -p /tmp/.mediaswg
There is a test specific to directories.  You can also set the mode when the directory is created:
Code: [Select]
[ -d /tmp/.mediaswg ] || mkdir -p /tmp/.mediaswg -m 777The -d test may cause trouble for mkdir if there is already a regular file of that name, although my guess is there shouldn't be one.

Quote
cat /home/"$USER"/.jwmrc-tray  | sed ...
You don't need to cat the file and pipe to sed.  You can use sed -i expression filename to edit the file in place with a single process.

Quote
sed blanks the line but leaves a newline
This is because you are substituting (s/old/new/) rather than deleting (/pattern/d).  Not tested, but I think it should work:
Code: [Select]
sed -i '/watcher2h/d;/adjvolumefifo/d' /home/"$USER"/.jwmrc-trayThe patterns may need adjusting if you have them in other lines that you need to keep.

Offline softwaregurl

  • Suspended
  • Full Member
  • ***
  • Posts: 109
Re: PPI question-where does what file go in original apps.
« Reply #12 on: June 08, 2009, 08:51:31 PM »
Thanks JLS for the link.  It helped a lot.
and thanks mikshaw for the cleanup tips.
and thanks curaga and roberts and jasonw and ... and ... and ...
the fifo problem disappeared suddenly and I have no clue why other then i changed keyboards.   ???  Maybe its been too long since it had a cold boot.
i stumbled on the symlink problem.  on boot $HOME is / but using appbrowser $USER is root so i was linking to /home/root/......
this fixed that for now but i will still hard code in for the app to find home later.
Code: [Select]
#link to local data
if [ ! -L /usr/local/mediaswg/localdata ]; then
  if [ "$USER" != "root" ]; then
    sudo ln -s /home/"$USER"/.mediaswg/localdata /usr/local/mediaswg/
  else
        sudo ln -s "$HOME"/.mediaswg/localdata /usr/local/mediaswg/
  fi
fi
anyway the first version is released on my site and submitted.
ttyl
-SG
Old wounds that have never healed need to be re-exposed before the cure can be applied.  The cure must be available before the wound is re-exposed.