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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With