Can't query startup status from cron start

I am running Ubuntu 14 and I added the following line to my crontab:

*/1 * * * * : testing; /usr/sbin/service my-service status > ~/status 2>&1

      

After the next minute, I see this in ~ / status:

my-service: unrecognized service

      

If I run this from the terminal it recognizes the service:

~$ /usr/sbin/service my-service status
my-service stop/waiting

      

I am wondering what could be the reason why my service is not recognized in the cron production environment but not in my environment when I ssh to the server?

+3


source to share


1 answer


I found this to work:

*/1 * * * * : testing; /sbin/initctl status my-service > ~/status 2>&1

      



/usr/sbin/service

works with SystemV jobs (for example, in /etc/init.d), and Ubuntu also deals with Upstart jobs (for example, in / etc / init). /sbin/initctl

works directly with Upstart jobs. So my guess is that the mechanism that allows the /usr/sbin/service

Upstart jobs to be seen does not work for some reason in the environment my cron job is running in, but I'm not sure how to investigate this further.

+6


source







All Articles