svc

system administrationLinux/Unix
The svc command is one of the most frequently used commands in Linux/Unix-like operating systems. svc Control services monitored by supervise or daemontools

Quick Reference

Command Name:

svc

Category:

system administration

Platform:

Linux/Unix

Basic Usage:

svc [options] [arguments]

Common Use Cases

    Syntax

    svc [options] service_directories...

    Options

    Option Description
    -u Up: start the service. If the service is already running, this has no effect.
    -d Down: stop the service. If the service is already stopped, this has no effect.
    -r Restart: send the service a TERM signal, and then restart it when it dies.
    -t Terminate: send the service a TERM signal.
    -k Kill: send the service a KILL signal.
    -p Pause: send the service a STOP signal.
    -c Continue: send the service a CONT signal.
    -h Hangup: send the service a HUP signal.
    -a Alarm: send the service an ALRM signal.
    -i Interrupt: send the service an INT signal.
    -q Quit: send the service a QUIT signal.
    -1 User1: send the service a USR1 signal.
    -2 User2: send the service a USR2 signal.
    -o Once: if the service is not running, start it. Do not restart it if it stops.
    -x Exit: Supervise will exit as soon as the service is down. If the service is down, supervise exits immediately.

    Examples

    How to Use These Examples

    The examples below show common ways to use the svc command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    svc -u /service/myservice
    Start the service in the /service/myservice directory.
    svc -d /service/myservice
    Stop (down) the service in the /service/myservice directory.
    svc -r /service/myservice
    Restart the service in the /service/myservice directory. # Advanced Examples Advanced # Stop multiple services at once svc -d /service/http /service/dns /service/ssh # Send TERM signal to a service svc -t /service/myservice # Send kill signal to a service svc -k /service/myservice # Immediately down and then up a service (full restart) svc -du /service/myservice # Pause a service svc -p /service/myservice # Continue a paused service svc -c /service/myservice # Tell a service to reopen its log files svc -a /service/myservice # Tell a service to send itself a SIGHUP svc -h /service/myservice # Tell a service to send itself a ALRM signal svc -a /service/myservice # Restart multiple services at once svc -r /service/http /service/dns /service/ssh # Control all services in a directory svc -d /service/* # Check status after sending a command svc -d /service/myservice && svstat /service/myservice # Custom signal (using SIGUSR1) svc -1 /service/myservice # Custom signal (using SIGUSR2) svc -2 /service/myservice

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The `svc` command is part of the daemontools package, which is a collection of tools for managing Unix services. Created by DJ Bernstein, daemontools provides a reliable and minimal approach to service supervision, ensuring that critical services stay running and can be controlled easily. At its core, `svc` (service control) is used to send signals to services that are monitored by the `supervise` program, another component of daemontools. The `supervise` program runs in the background, continuously monitoring a service and restarting it if it crashes. The `svc` command allows administrators to control these supervised services without having to interact directly with `supervise`. Unlike traditional init systems like System V init or systemd, daemontools takes a Unix philosophy approach to service management: each tool does one thing well. The `svc` command specifically handles sending control signals to services, while other tools in the suite handle different aspects of service management: - `supervise` - Monitors and restarts services - `svstat` - Reports the current status of services - `svok` - Checks if supervise is running properly - `svscan` - Scans a directory for services to supervise The daemontools approach to service management revolves around the concept of service directories. Each service has its own directory containing at minimum a `run` script that starts the service. The `supervise` program watches this directory and maintains control over the service. To use `svc`, you specify one or more of these service directories as arguments, along with the option that indicates what action you want to perform. The `svc` command then communicates with the appropriate `supervise` process via a control socket in the service directory. While newer service managers like systemd have become the standard in many Linux distributions, daemontools (and derivatives like runit, s6, and nosh) continue to be valued for their simplicity, reliability, and adherence to Unix design principles. They are particularly popular in container environments, minimal distributions, and systems where service reliability is critical. The `svc` command provides a clean, straightforward interface for service control that works well in both interactive and scripted contexts, making it a valuable tool for system administrators who prefer the daemontools approach to service management.

    Related Commands

    These commands are frequently used alongside svc or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the svc command works in different scenarios.

    $ svc
    View All Commands