Ubuntu – Running a command at startup

daemonremindUbuntu

I recently came across "remind" in Linux. I liked it almost immediately, but for my reminders to pop up, I needed to run 'remind' in daemon mode. Done quite simply using the following command:

remind -z -k'gmessage %s &' /home/googie/.reminders &

It would be lame for me to manually launch the 'remind' daemon every time I boot my computer (someone would have to remind me to do that!), so I thought I'll make it run automatically on boot. I was under the impression that this would be fairly straightforward to do, but I was in for a surprise.

I did the following (in this sequence):

  1. Made a script (with start, stop, restart cases), placed it in /etc/init.d, ran 'update-rc.d' to create some links for certain runlevels, restarted — no luck
  2. Made a 'remind.conf' file, placed it in /etc/init (referring 'http://upstart.ubuntu.com/getting-started.html'), restarted — still no luck
  3. Opened '/etc/rc.local', placed the command to start the 'remind' daemon just before 'exit 0', restarted — still no luck
  4. Opened crontab (sudo crontab -e), wrote '@reboot' followed by the command to start the 'remind' daemon on the last line, restarted — still no luck
  5. Opened 'System->Preferences->Startup Applications', added a new startup program with the command to start the 'remind' daemon, restarted — still no luck
  6. Made a script in my home directory, placed the command to start the 'remind' daemon inside the script, called this script from '/etc/rc.local', restarted — still no luck
  7. Called the script in my home directory after '@reboot' in crontab, restarted — still no luck
  8. Called the script in my home directory using 'System->Preferences->Startup Applications' — finally worked, and the 'remind' daemon now runs!!

So now for my 3 questions:

  1. Is it really so complicated in Linux to run something at startup, or is it just my lack of knowledge?
  2. Was trying steps 1 & 2 even advisable? I think these are used to make something a service. Isn't the 'remind' daemon a service as well?
  3. Why didn't the '/etc/rc.local' or 'crontab' approach work? Are there any logs I could check to see what's going wrong?

(any related references for me to read would be appreciated as well)

Best Answer

1) I'm afraid that it's the latter. But don't feel bad, most people trip over it.

2+3) The only ones that would have a chance of working are 5 and 8. The startup scripts and cron have no idea of your login session, so there's no way they could point remind or gmessage in the right direction. And 5 didn't work because the ampersand at the end is a feature of the shell, not the command. You likely don't even need it if the command is being run as a startup application.

Related Question