My task is to start a process on startup if it was running before shutdown. To achieve this, I have added a command in /etc/init.d/halt.local to save the state of process in a file.

In /etc/inittab, I added command to read file and start the process based on state recorded. But the process is not coming up. I can see that the state was recorded properly while shutdown, and also few other commands I added to /etc/inittab which are executing properly, but not the one needed.

Content added to inittab:

ec1:235:once:/bin/echo "Started..." > /tmp/pankaj3.txt
rly:235:once:/bin/su - user -c '[[ `head -1 /tmp/pankaj/.status` == STARTED ]] && { /opt/my_user/bin/ctrl.sh start ; }'

On executing the command on terminal, its working fine. The output is:

SS-01:~ # /bin/su - user -c '[[ `head -1 /tmp/pankaj/.status` == STARTED ]] && { /opt/my_user/bin/ctrl.sh start ; }'
[07-10-2015] 10:33:00 ctrl.sh[18008]: Management Process started.

The other line added to inittab ec1:235:once:/bin/echo "Started..." > /tmp/pankaj3.txt is executed.

Please help me to get where I am doing wrong.

  • Possibly an environmental issue; compare the output of printenv in working and non-working situations. – Jeff Schaller Oct 7 '15 at 10:28
  • How do you know /tmp is mounted when your command is being run when you enter level 2? or 3?. IMO this is not the way to go, if you want to start a process you should do it creating a script in /etc/init.d and linking that script to the right run level directory (/etc/init.d/rc0.d, rc1.d, etc...) if you are running a sysinit system, if instead it is a systemd or upstart you will need to check how it is done in those. – YoMismo Oct 7 '15 at 10:36
  • 2
    You have to be specific about what you mean by "unix", because on a lot of operating systems (both Unices and Unix-alikes) there's a good reason that things in /etc/inittab have no effect. Tell people in your question what operating system this is. Then they'll know what the likely semantics of /tmp are, for starters. They'll still tell you that an asymmetric design that has half of the task done by an init-spawned process and the other half by an rc subscript is a poor one, though. ☺ – JdeBP Oct 7 '15 at 10:44
  • @JdeBP...I am using SUSE Linux Enterprise Server 11 (x86_64). Also, I tried by modifying the command as rly:235:once:/bin/su - user -c '/opt/my_user/bin/ctrl.sh start', and it executed. But not sure why a condition it is not accepting. – pankaj_ar Oct 7 '15 at 11:34
  • Is perhaps systemd being used instead of the old SystemV init? Is /sbin/init a symlink and if so where is it pointing to? – wurtel Oct 7 '15 at 12:55

It sounds like SUSE Linux ES 11 uses the traditional System V init system (sysvinit). Suse Doc | The init Process

You can see man inittab(5) for documentation of the syntax.

Firstly, it could be that inittab doesn't support shell features such as redirection and compound commands, which are only supported in the shell. Altho you say your first command works, which suggests that's not the reason.

Secondly, su runs /bin/sh by default, which might not support [[.

Thirdly, files in /tmp are usually deleted during boot, so if you created /tmp/pankaj/.status during shut down, it's almost certainly not there after rebooting. Check if that file is present.

In any case, you should make it a separate init script that uses your expected shell as the #! line, put it in /etc/init.d/pankaj (or whatever), and make it run at levels 2, 3, and 5 with chkconfig.

The Init Scripts section of the SUSE Administration Guide provides some tips for getting started with that.

Lastly, if all you're trying to do is make a service restart on boot if it was previously running, then don't. chkconfig is the standard tool for configuring something to start at boot. It's what every other service on your system uses. Making one service act differently will just confuse things.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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