Article 10 of 15
Managing Services on BcalcOS
How do you check whether a service is running? How to stop or restart it?
Checking a Service’s Status
Let’s use cron as our example. We know that cron runs scheduled tasks in the background.
Were we to open a terminal and enter: /etc/init.d/cron status we’d likely see a return of “cron is running.”
For services, the output from status depends on the script and the current state of the service.
Checking a service’s status usually doesn’t require administrative privileges.
Starting, Stopping, and Restarting a Service
Unsurprisingly, the same general approach applies to other service actions.
To start cron: sudo /etc/init.d/cron start
To stop cron: sudo /etc/init.d/cron stop
To restart it: sudo /etc/init.d/cron restart
These commands request an action from the service’s init script.
Unlike checking on the status, administrative privileges are generally required to make changes to a system service, hence sudo.
Be sure to understand what a service does before stopping it. Stopping a logging service, for example, can interrupt logging; stopping a network-related service can affect connectivity.
BTW, a successful command doesn’t necessarily prove that the service is fully functional. If a service fails to start, its output and relevant logs may provide further clues.
Some services also support reload, which reloads configuration without stopping the service. This is useful for services like rsyslog where restarting might interrupt active tasks.
Managing a Service /= Enabling It at Boot
Starting a service tells it to run now. Configuring it to start automatically tells the system what to do during a future boot.
A service can be running now without being configured to start automatically at the next boot. Conversely, a service can be configured for automatic startup but fail when the system attempts to start it.
To check whether a service is enabled for automatic startup, look at the runlevel configuration: ls /etc/rc2.d/ | grep cron
If you see S0xcron, the service is enabled to start in runlevel 2. If you see K0xcron, it is configured to stop. If neither appears, the service has no startup configuration for the runlevel.
What If a Service Won’t Start?
A failed service doesn’t automatically mean SysVinit itself is broken. The problem might be within the application, a missing configuration file, unavailable resources, permissions, or a dependency that isn’t working.
A basic troubleshooting first step is to check the service’s status and read any error output produced when attempting to start it.
A Note About Commands on Other Systems
Systemd-based systems use ‘systemctl’ while some Debian-based systems use the service wrapper both of which allow the user to type service cron start instead of calling the init script directly.
The effect is the same so you can translate their service cron start to our /etc/init.d/cron start.
Key Takeaway
Common commands for everyday service management on BcalcOS are:
/etc/init.d/NAME statusto check a service’s statussudo /etc/init.d/NAME startto start itsudo /etc/init.d/NAME stopto stop itsudo /etc/init.d/NAME restartto restart it
To check if a service is enabled at boot: ls /etc/rc2.d/ | grep NAME.