LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   MEPIS (http://www.linuxquestions.org/questions/mepis-64/)
-   -   How Do I Create A Startup Script? (http://www.linuxquestions.org/questions/mepis-64/how-do-i-create-a-startup-script-503935/)

joany 11-22-2006 10:24 AM

How Do I Create A Startup Script?
 
How do I create a startup script to run an application in background during/after booting up? The application in question is already installed. I presently use a desktop icon to launch it immediately after booting up, but I really would rather have it launch itself automatically. Does this have anything to do with "daemons" and such?? Please provide a step-by-step example of how to do this, since I am quite new to Linux and need a lot of hand holding at this stage!

Thanx

fordeck 11-22-2006 10:34 AM

What is the application?

What distro are you using?

joany 11-22-2006 12:01 PM

Startup Script
 
fordeck,

I'm using Mepis, which I believe is a variation of Debian, and the application I want to launch is VMware-Toolbox.

fordeck 11-22-2006 01:27 PM

I'm not real familiar with Mepis. However I believe you could append the VMware-Toolbox statement into your user's ~/.profile file so that every time you login it is run.

joany 11-22-2006 02:12 PM

fordeck,

Thanks for getting back to me. I opened a terminal and typed "locate .profile" and got hits on a number of files in the form *.profile, including one named "/usr/share/base-files/dot.profile"

When I open the file in a text editor, there is a header that says:

"# ~/.profile: executed by Bourne-compatible login shells."

Is this the file I should try to append? What is the proper syntax for a line of script that starts an application from this file? For example, if the terminal command to start the application is "vmware-tools," is that all I need to append to the script? Or should the syntax be: "vmware-tools start" in the script?

I'm sorry for asking such stupid questions, but as I said earlier, I need a lot of help at this stage.

Thanks in advance for your help ...

fordeck 11-22-2006 04:21 PM

The .profile I spoke of would be in your user's home directory for example:

/home/joany/.profile

This file is ran everytime you login. You could append something like this to the bottom of .profile:

Code:

if [ -x /<path-to-vmware-tools>/vmware-tools ]; then
          /<path-to-vmware-tool>/vmware-tools
fi

However this approach could cause problems. Like I said earlier .profile gets executed everytime you login. A better approach would be to create a PID or process id file when vmware-tools starts, and have the script check for its existence. I'll have to see if I can create something that would do that.

joany 11-23-2006 09:48 AM

fordeck,

Thanks for your time and trouble. I log in as "username", but unfortunately, I cannot locate a file named /home/username/.profile on my system.

It may be that Mepis uses a different naming convention for the profile file than the distro you're using. I'll try adding the lines of code you suggested in your last post into the /usr/share/base-file/dot.profile file and see what happens. Having the code run every time I log in should not be a problem.

As you might have guessed I'm running Mepis on a virtual machine (VMware) instead of from a full install, so there's no harm in trying this out. I'm presently taking Mepis for an extended "test drive" before doing a full install. So I'll back up my virtual file system and if things get out of hand and "blow up," I can easily restore everyting back to normal from the back up copy.

Thanks again...

fordeck 11-23-2006 10:10 AM

Your right, I don't use Mepis so maybe they do it differently. You could also create one in your home directory and see if that works. The file you mentioned above /usr/share/base-file/dot.profile is probably a template file for users personal .profile files. You probalbly already know this but just in case. Files that begin with a "." are hidden files and can be listed by:

ls -a

or you can view the contents like this:

cat ~/.profile

joany 11-24-2006 12:55 PM

fordeck,

You may be quite right about the /usr/share/base-file/dot.profile being only a "template" file. I'll try creating a new hidden file named /home/username/.profile containing the lines of code you suggested in your 11-22-06 5:22PM post. I'm at a friend's house and will get back to testing Mepis on my computer next Monday. I'll post the results early next week.

Thanks once again and cheers.

joany 11-27-2006 05:53 AM

fordeck,

Following your suggestion, I created a file named /home/username/.profile and wrote the following lines of code using a text editor:

if [ -x /usr/bin/vmware-tools ]; then
/usr/bin/vmware-tools
fi

I verified that the .profile file had been saved in the proper folder, then I rebooted the machine and logged in as username. Unfortunately, it seems that the script I wrote in the .profile file failed to execute during the sign-on sequence, because vmware-tools wasn't running and I had to start it manually.

fordeck 11-27-2006 10:00 AM

One other possibility might be to use "/etc/rc.d/rc.local". This path is relative to a Fedora installation. Your rc.local might be in another location. The rc.local file is executed after all other runlevel scripts have run at bootup. Again this file only runs at system bootup. Also it would probably be a good idea to run vmware-tools in the background so one small modification to the code:

Code:

if [ -x /usr/bin/vmware-tools ]; then
/usr/bin/vmware-tools &
fi

The ampersand added to run it in the background.

joany 11-27-2006 04:20 PM

fordeck,

Thanks once again for your trouble. I agree that it would be preferable to run vmware-tools in the background, and I'll add the "&" to the code to do that.

I did some research and learned that by default, VMware is supposed to automatically launch while the Linux guest OS boots. But it seems that Mepis doesn't fully support all of VMware's features, which is why I'm having this problem. It could be that Mepis uses different startup files than the other distros.

I won't have time to try out your most recent suggestion until tomorrow -- I'll post the result then.

Cheers

joany 11-28-2006 07:21 AM

Okay...

I located a file named /etc/rc.local. The file header states that the script is executed, "At the end of each multiuser run level."

There is another file named /etc/init.d/rc.local. The script contained in that file calls /etc/rc.local, so I thought the logical choice was to insert the script that launches vmware-tools into /etc/rc.local. Using root privileges, I edited /etc/rc.local, saved the file, rebooted, and logged in under username. As before, vmware-tools was not running after I logged in and I had to start it manually.

Finally, I said, "What the heck," and inserted the script to launch vmware-tools into /etc/init.d/rc.local, saved the file, rebooted and logged in. Same result: Vmware-tools was not running.

At this point, I'm not at all sure that my script is even being accessed during boot-up or logging in. Is there some way to display some sort of message or banner that would verify that the script I added is actually being read? That could help pinpoint whether there is a problem with the script itself or if the script simply is being ignored.

This has been quite educational for me, even though we haven't solved the problem!

joany 11-28-2006 12:58 PM

... Continued

It seems that with Mepis, any executable files that are saved in the folder /home/username/.kde/Autostart will start automatically when "username" logs in.

Now my question is how can I create a script file (from scratch) that launches itself from that folder? Can one use any text editor (like GEDIT) to create such a script file, or is a special editor required? How should I save such a file; i.e., what is the convention for naming executable script files?

I used GEDIT to create a file named "vmware" with script code in it. Then I saved this file into the Autostart folder. However, when I logged in, GEDIT launched itself and displayed the text in the "vmware" file, instead of executing the script that I wrote in the file.

I think I'm close to finding the solution to this problem and I'm sure the solution will turn out to be fairly simple, but I could definitely use some more help at this point.

fordeck 11-29-2006 10:15 AM

Joany,

Sorry for the delay, I think your on the right track. I think all you would have to do in /home/username/.kde/Autostart is create a symbolic link to vmware-tools. For example:

Code:

ln -s /usr/bin/vmware-tools /home/username/.kde/Autostart/vmware
This will create the symbolic link, similar to a shortcut in windows. I haven't tested this yet but I will and I'll get back to you.


All times are GMT -5. The time now is 06:09 PM.