Run application at startup

This is a discussion on Run application at startup within the Linux Programming forums, part of the Platform Specific Boards category; We have a Windows Service written in C# ported over to linux using Mono Develop... The code is working 100% ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    2

    Run application at startup

    We have a Windows Service written in C# ported over to linux using Mono Develop... The code is working 100% when we run a script file which runs the exe... but we want the application to run at startup.... The application gathers info of the computer eg. Hard Disk Space etc... And compress it into a .zip file and then calls a web service method to upload the data... Any ideas on how to get it running at startup?

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    The general concept is to use an "init script".* These are for the unix shell (/bin/sh) and go into a directory in /etc (usually, /etc/init.d). These are run by init, which is the first process started by the kernel. Since linux distros are heterogeneous, there are various forms of init daemon; traditionally, the services managed by init scripts are organized into "run levels" (for single user, multi-user, networked, gui) by using symlinks from a set of directories in /etc/rc.d. While not all distos still use that exact system, all of the ones that I have ever seen do use init scripts, and those scripts have the same basic structure.

    http://www.linux.com/learn/tutorials...h-init-scripts

    Ie, the form of the script in that tutorial is what you want, but

    1) Sourcing /etc/init.d/functions should be mostly portable, but it is not necessary.

    2) Don't count on specifics with regard to the nature of runlevels etc. Fortunately, these are not referenced in the script itself anyway.

    Some distros elaborate on this model, eg, by incorporating prerequisites directly into the script, but again, AFAIK this should not be necessary as the idea is to respect the basic common form.

    My advice to you is to write the script, incorporating the start, stop, restart, and status functions, and then simply distribute it with your package and include some documentation to let the user know it is available. Since there is no universal system WRT exactly how the scripts get used, trying to automate the install will just lead to "works some places, doesn't work others".

    OTOH, you could test to see if the system uses a SysV like /etc/rc.d with runlevels, and auto-install if that is available, since it is the most common. I presume starting a mono application will rely on various services already existing, so most likely you will want to have the script start late, after the system goes online -- and only in runlevels where networking is started. Unfortunately, that is complicated by the fact that startup services are user configurable, so again, my advice is to just provide the script and let the user install it appropriately.

    * if you google, don't confuse this with:
    http://linux.about.com/library/cmd/b...initscript.htm
    Which is obscure, so some people may use the term "initscript(s)" but most likely are not referring to that.
    Last edited by MK27; 12-02-2011 at 06:50 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Application fails to load settings only at windows startup
    By DanFraser in forum C# Programming
    Replies: 3
    Last Post: 09-27-2009, 11:15 AM
  2. my method to optimize application startup performance
    By George2 in forum C Programming
    Replies: 17
    Last Post: 11-22-2007, 10:26 PM
  3. Startup using STARTUP folder method for winXP & win98
    By hanhao in forum Windows Programming
    Replies: 2
    Last Post: 05-26-2005, 04:59 AM
  4. Run on Startup ?
    By Korhedron in forum Windows Programming
    Replies: 9
    Last Post: 01-05-2004, 02:57 PM
  5. need help with startup
    By excessone in forum Windows Programming
    Replies: 6
    Last Post: 02-06-2003, 01:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21