I made a small utility application in C that monitors udev for power events and adjusts my laptop backlight brightness automatically. (I'm running Ubuntu 15.04)

I ran the following commands and it runs on startup just fine.

$ sudo cp powermonitor /etc/init.d/powermonitor
$ sudo chmod +x /etc/init.d/powermonitor
$ sudo update-rc.d powermonitor defaults

However, after monitoring its CPU usage in htop for a while, I noticed that it is now gone. The program takes no command line arguments, though it seems Linux is trying to start it with:

/etc/init.d/powermonitor start

Is there something I should be doing to ensure that the process keeps running?

EDIT: To clarify, powermonitor is an executable and not a script.

  • 1
    Usually instead the init.d/* file is a shell script that then calls powermonitor; look at the other files therein for examples.
    – thrig
    Sep 8 '15 at 23:30
  • Your program is probably crashing. This should generate a log entry but I don't know where systemd puts it. Sep 9 '15 at 0:04
  • Same thing is happening for me, and no, the program is not crashing. I just cannot find any evidence that it's even started. The script itself is running.
    – Owl
    Dec 13 '18 at 14:01

The files in /etc/init.d are not supposed to be compiled executables. You put your compiled executable somewhere else, maybe /usr/local/bin; then you write an init script in /etc/init.d, which knows how to start and stop the compiled program. Often this is as simple as running it in background to start, and killing its PID (or its executable name using killall) to stop. init will call the init script with a single argument, the word start, stop, restart &c.; it's the script's responsibility to know about how to run the service itself.

For a quick intro, try here. There may well be an example skeleton script in your /etc/init.d directory that you can alter to suit your case.

As a side note, what distro are you running? Many modern distros now run systemd instead of sysvinit, which uses (by default) a declarative unit file rather than an init script; IMO unit files are easier to write. systemd provides a sysvinit compatibility mode, so it's possible you're running it yourself. If so, I'd recommend writing a unit file rather than a script.

  • I'm running Ubuntu 15.04. Thanks for the response; I'll take a look at the link and some of the scripts. If this helps, I'll mark it correct! Sep 9 '15 at 0:35
  • I think the compiled program was crashing, but I'm marking this as correct because it taught me something about how /init.d should be used. The crashing issue is separate from this question in many senses. Sep 9 '15 at 11:40

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.