Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't query upstart service status from cron job

I'm 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 rolls around, I see this in ~/status:

my-service: unrecognized service

If I run this from the terminal, it does recognize the service:

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

I'm wondering what could be responsible for my service being unrecognized in the cron job's environment but not in my environment when I ssh to the server?

like image 676
nonagon Avatar asked Dec 04 '25 17:12

nonagon


1 Answers

I found that this works:

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

/usr/sbin/service works with SystemV jobs (e.g. those in /etc/init.d), and under Ubuntu it also sees Upstart jobs (e.g. those in /etc/init). /sbin/initctl works directly with Upstart jobs. So my guess is that the mechanism that allows /usr/sbin/service to see Upstart jobs isn't working for some reason in the environment my cron job runs in, but I'm not sure how to explore that further.

like image 163
nonagon Avatar answered Dec 06 '25 22:12

nonagon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!