Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
    
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. –  Nils Jul 14 '12 at 20:48
    
What distribution are you using and what do you mean with inittab script? –  Ulrich Dangel Jul 15 '12 at 23:16
    
@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 Jul 16 '12 at 12:11
add comment

4 Answers

up vote 4 down vote accepted
+50

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.

share|improve this answer
    
Thanks for your help, this has been driving me crazy, this is very will hidden compared to using inittab –  Boardy Jul 16 '12 at 17:25
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
    
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 Jul 14 '12 at 13:45
    
@Boardy Did you try with an absolute path for the log file? Do you see the Re-reading inittab message? –  Gilles Jul 14 '12 at 18:37
    
Yep, I tried that and it is saying that it is reloading after I run telinit q –  Boardy Jul 15 '12 at 19:18
add comment

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|improve this answer
    
Hi Thanks for your help, neither of those worked, both attempts the program doesn't run –  Boardy Jul 14 '12 at 16:12
    
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? –  Marios Zindilis Jul 14 '12 at 16:18
    
Yep, if I can run it from any location on the server not necessarily where the file is stored and the program launches successfully. –  Boardy Jul 14 '12 at 16:20
    
@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 Jul 14 '12 at 20:37
    
@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 Jul 15 '12 at 16:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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