I am using Ubuntu 14.04. I wrote a small script named trial. The contents of the script are as follows:

 #!/bin/sh
SHELL=/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin     
sh -c firefox

I copied the script to /etc/init.d, modified permission using chmod +x trial and used update-rc.d trial defaults. The file made link but when I rebooted the machine. It did not run firefox. I tried cron @reboot but with no success. I tried rc.local too again failure.

  • Chrisopher is right about why this doesn't work. You might want to explain why you want to do this as there are alternatives but they depend on distinuishing, e.g. "I want firefox to start automatically on my desktop," from, "I want the system to act as a kiosk for firefox". – goldilocks May 22 '14 at 11:34
  • @Parthe - I always test this feature using writing to a file first. If that works then the @reboot is working. I'm not sure the system will launch GUI's from cron, is there any particular reason you want to do this that way? I would be more inclined to make the launching of a GUI part of a user's startup. – slm May 22 '14 at 11:36
up vote 7 down vote accepted

The directory, /etc/init.d/ contains system scripts that essentially start, stop, restart daemons (system services). It's the "System V Initialization" method (SysVinit), containing the init program (the first process that is run when the kernel has finished loading). (EDIT 2 July 2015: Many Linux systems have recently switched to the systemd init system.)

But, Firefox is a graphical Web browser. As such, it needs the window server (X-Windows) and window manager to be started; and, you would need to be logged into the window manager to start Firefox. So, the task for you is to learn how to automatically start a program after you have logged into your window manager.

Find the name of your window manager. Then search for help about automatically starting a program.

  • Thanks for the clarification, I just need to run a jar file as a daemon process. So can I run a jar file that just prints out something and if it runs, it is an indication that my jar file too will run right? – Joker May 22 '14 at 12:59
  • Thanks for the reply. I need my jar to run in all *nix based systems at startup. So I need to search a way that comes with the OS. – Joker May 23 '14 at 5:25

I wouldn't expect this to work either. Even though you've wrapped the launching of Firefox in a script it isn't truly a script in the sense that it can be run during startup of the system. For example, in order for Firefox to launch it would need X running and access to open a GUI on a particular session of X.

I would attack the problem in a slightly different way using one of the methods discussed below. In particular I typically use the alternative approach.

Usually you put X related items that you'd like to run in the context of the user (you) in one of 2 files:

  • $HOME/.xsession
  • $HOME/.xinitrc

  • For GNOME desktops you can put commands in $HOME/.gnomerc

  • For KDE you put commands in $HOME/.kde/Autostart

Alternative Approach

Some commands such as xset may not work from within these files. If you'd still like to automate something like this you may be able to add it as a "Startup Application".

Step #1

Create a shell script, xset.bash.

#!/bin/bash
xset r rate 120 66
Step #2

Add a startup task to run the shell script.

Open the application Startup Applications, under System → Preferences

                    ss of dialog #1

Then click the Add button

                                ss of add dialog

Once you're done OK & Close the dialogs and to test it out logout and log back in.

References

  • Thanks for the reply. I will try to run a simple jar file and test it. – Joker May 22 '14 at 12:59

This answer to Firefox won't open on startup gives a little more information and worked great for me:

The global autostart file, /etc/xdg/lxsession/LXDE-pi/autostart, is ignored if you have a local autostart file in your home directory, ~/.config/lxsession/LXDE-pi/autostart. If you have a local autostart file, you need to use that instead of the global one (or remove the local autostart file). Anything you put in the global autostart file will be ignored if a local file exists. You can edit your local autostart file with: nano ~/.config/lxsession/LXDE-pi/autostart (or use your editor of choice). If the file does not yet exist, you can rule this out.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.