Add item to inittab on OpenSuse 12.1

6,896

Solution 1

The problem is simple, you are using OpenSuse 12.1 which uses systemd instead of your classic System V boot system.

To install a new service place create following file in /etc/systemd/system/myprogname.service

[Unit]
Description=My progname service file

[Service]
ExecStart=/home/bits/MyProgram

[Install]
WantedBy=multi-user.target

Aftwards run systemctl daemon-reload and systemctl start myprogname.service

If you want to automatically restart MyProgname you have to add

Restart=restart-always

to the service section.

Solution 2

Put your program somewhere.

Copy and edit the skeleton template file for init job control found at /etc/init.d/skeleton.

Modify this file to indicate WHICH runlevel you want... in your example, you want 2,3,4,5, there are options at top of file (in comments) to indicate desired runlevels

Place this new file in /etc/init.d with a descriptive name. (myfancyname used in example)

A platform agnostic method to test this, or to enable/disable (if you used the skeleton file)

sudo /etc/init.d/myfancyname start
sudo /etc/init.d/myfancyname stop
sudo /etc/init.d/myfancyname restart

There are distribution specific methods to perform these same actions, for instance, Debian uses update-rc.d myfancyname [start|stop|enable|disable...]

Modifying inittab is generally a bad idea, if you screw it up, the system no longer boots, and then you've got TWO problems. (no regex needed!)

Adding scripts to the /etc/init.d/ subdirectory is more standardized, can be used with almost ANY linux flavor, probably some *nix's, maybe some bsd's.

Solution 3

You need to run telinit q to tell init to reload /etc/inittab, it won't do that automatically. I think you've done that since you mention the Re-reading inittab message (you did see this message, right?) in the system logs.

Is the problem that your process isn't starting at all, or that your program fails during its startup? Write a wrapper script that redirects errors to a log file:

#!/bin/sh
exec >/var/log/myprogram.log 2>&1 
exec /home/bits/MyProgram/start.myprogram

Check if the log file is created and see if any errors appear in it.

One thing that comes to mind is that your program may require environment variables that are set in your session. The init process has a very limited environment. If necessary, modify the wrapper script to set all needed variables.

Solution 4

When init reads a Command to execute in inittab, it forks a shell and sends the Command as a parameter to the exec command in that shell. So, check what happens if you manually do:

sh -c exec /home/bits/MyProgram/start.myprogram

Another thing that I would try, would be to bypass the launcher script altogether, with something like this in inittab:

bes:2345:respawn:/usr/bin/mono /home/bits/MyProgram/EmailServer.exe "$@"
Share:
6,896
Boardy
Author by

Boardy

Develop apps and services in PHP, C#, C++, HTML, CSS, Jquery etc, recently started learning React.

Updated on September 18, 2022

Comments

  • Boardy
    Boardy over 1 year

    I am currently working on a project which needs to be added to inittab so that the program loads during startup.

    The program that I am trying to start is a c# mono application. I have created a start script and if the start script is run manually the program launches fine. However, when I put it into inittab the program doesn't launch.

    I've checked in /var/log/messages but it doesn't say anything is wrong, it just says that it is reloading.

    Below is what I have added to my inittab script

    bes:2345:respawn:/home/bits/MyProgram/start.myprogram
    

    Thanks for any help you can provide

    UPDATE Below is the code in the start script which is located in /home/bits/MyProgram.

    #!/bin/sh
    
    cd /home/bits/MyProgram
    
    /usr/bin/mono EmailServer.exe "$@"
    

    I have also tried adding > mylog.txt onto the end of the line beginning with /usr/bin/mono e.g.

    /usr/bin/mono EmailServer.exe "$@" > mylog.txt

    If I run the start script manually, even if I am not in the directory where the start script is located it works fine, its just when I add it to inittab and run telinit q it never starts and the log isn't written to but the log does get written to if I start the program manually.

    Thanks for any help you can provide.

    • Nils
      Nils almost 12 years
      Bad enough that you use mono on a linux system. But placing it into inittab is horrible. Go for a proper /etc/init.d/ script.
    • sunnysideup
      sunnysideup almost 12 years
      What distribution are you using and what do you mean with inittab script?
    • Boardy
      Boardy almost 12 years
      @UlrichDangel I'm using OpenSuse 12.1 and by inittab I mean /etc/inittab which is where you can add things to load up on startup.
  • Boardy
    Boardy almost 12 years
    Sorry for taking a while to get back to you, my test virtual machine stopped working took me a while to work out what was wrong. Anyway, I've tried what you suggested but that doesn't start either, its not my program failing to start, its just not ever starting the program. I've added the content of my start script to my question in case it helps.
  • Boardy
    Boardy almost 12 years
    Hi Thanks for your help, neither of those worked, both attempts the program doesn't run
  • DataBased
    DataBased almost 12 years
    If the program doesn't run with the first command, it won't run from inittab, so you need to temporarily ignore inittab and troubleshoot why the script doesn't launch generally. Is /home/bits/MyProgram/start.myprogram executable?
  • Boardy
    Boardy almost 12 years
    Yep, if I can run it from any location on the server not necessarily where the file is stored and the program launches successfully.
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' almost 12 years
    @Boardy Did you try with an absolute path for the log file? Do you see the Re-reading inittab message?
  • Boardy
    Boardy almost 12 years
    @MariosZindillis Just found out if I run the executable, instead of the start script using exec /home/bits/MyProgram/EmailServer.exe it comes up with an error stating -bash: /home/bits/EmailServer/EmailServer.exe: Permission denied -bash: exec: /home/bits/EmailServer/EmailServer.exe: cannot execute: Permission denied
  • Boardy
    Boardy almost 12 years
    @MariosZindillis I've just tried running a basic script that doesn't attempt to execute my program, it will instead just write a word to a file and this file never gets written but if I run the script manually it does.
  • Boardy
    Boardy almost 12 years
    Yep, I tried that and it is saying that it is reloading after I run telinit q