웹사이트 검색

초보자를 위한 Linux 서비스 명령 자습서(예제 포함)


이 페이지에서

  1. Linux 서비스 명령
  2. 서비스 명령어는 어떻게 사용하나요?\n
  3. 결론

service 명령을 사용하면 System V init 스크립트를 실행할 수 있습니다. 이 자습서에서는 이해하기 쉬운 몇 가지 예를 사용하여 이 도구에 대해 간략하게 설명합니다. 하지만 그 전에 여기에 있는 모든 예제가 Ubuntu 18.04 LTS 시스템에서 테스트되었음을 언급할 가치가 있습니다.

Linux 서비스 명령

Linux에서 서비스 명령에 사용할 수 있는 구문은 다음과 같습니다.

service SCRIPT COMMAND [OPTIONS]

service --status-all

service --help | -h | --version

매뉴얼 페이지에서 설명하는 방법은 다음과 같습니다.

service  runs  a System V init script or systemd unit in as predictable an environment as possible,
removing most environment variables and with the current working directory set to /.

The SCRIPT parameter specifies a System V init script, located in /etc/init.d/SCRIPT, or the name
of a systemd unit. The  existence of  a  systemd unit of the same name as a script in /etc/init.d
will cause the unit to take precedence over the init.d script. The supported values of COMMAND
depend on the invoked script. service passes COMMAND  and OPTIONS to the init  script  unmodified.
For systemd units, start, stop, status, and reload are passed through to their systemctl/initctl
equivalents.

All  scripts  should  support at least the start and stop commands.  As a special case, if COMMAND
is --full-restart, the script is run twice, first with the stop command, then with the start
command.

service --status-all runs all init scripts, in alphabetical order, with the status command. The
status is [ + ]  for  running  services,  [  -  ]  for  stopped services and [ ? ] for services
without a status command.  This option only calls status for sysvinit jobs.

서비스 명령어는 어떻게 사용하나요?

서비스 명령줄 도구의 사용법은 전혀 복잡하지 않습니다. httpd 및 sshd와 같은 스크립트를 처리할 때 이 유틸리티를 사용하는 방법에 대해 이야기하겠습니다.

서비스를 사용하여 스크립트를 실행하는 방법은 다음과 같습니다.

service httpd start

서비스를 사용하여 이미 실행 중인 스크립트를 중지하는 방법은 다음과 같습니다.

service sshd stop

다음은 스크립트의 상태를 가져오는 방법입니다.

service httpd status

이미 실행 중인 서비스를 다시 시작하고 실행하는 방법은 다음과 같습니다.

service sshd restart

결론

Linux 사용자의 권한에 따라 sudo 명령어를 사용하여 위의 모든 예시를 실행할 수 있습니다. 서비스 명령에 대해 자세히 알아보려면 해당 매뉴얼 페이지로 이동하십시오.