linux - rc.local

System/Linux 2014. 3. 2. 17:35



Back in the good old days of Linux/UNIX, there was a file (usually) located under “/etc/rc.local” that would, after all run-level specific processes have been started, run whatever scripts were in the rc.local file. With Fedora Linux moving away from the more traditional “sysvinit” service manager, this rc.local file no longer exists for running whatever of your own bash scripts/commands you might want to run after the run-level specific processes have been started.

Luckily, you can re-enable this functionality :-) Obviously, you’ll need to be root for this so if you’re not already, elevate yourself to the root user:-

su - root

Then you need to re-create the rc.local file with:-

touch /etc/rc.local

chmod +x /etc/rc.local


Next, open the file for editing:-

vi /etc/rc.local

As this is basically a bash script itself, you need to include the bash interpreter as the first line of the file.

#!/bin/bash

You can now add whatever scripts or commands you like here – they will be run after everything else at your specific run-level has been started. In order for systemd to recognise and use this file, the systemd rc-local.service must be enabled.

systemctl enable rc-local.service

You can check the status of this service with:-

systemctl status rc-local.service

That’s all that’s required. Anything contained in this rc.local file will now be executed last-thing on reboot. Enjoy!


출처 - https://ask.fedoraproject.org/en/question/26898/what-is-the-auto-start-file-like-rclocal/

http://joshua14.homelinux.org/blog/?p=1377








[root@fedora17 etc]# systemctl enable rc-local.service

The unit files have no [Install] section. They are not meant to be enabled using systemctl.

[root@fedora17 etc]# systemctl status rc-local.service

rc-local.service - /etc/rc.d/rc.local Compatibility

 Loaded: loaded (/usr/lib/systemd/system/rc-local.service; static)

 Active: inactive (dead)

 CGroup: name=systemd:/system/rc-local.service


#ln -s /etc/rc.d/rc.local /etc/rc.local








리눅스나 유닉스는 워낙 종류가 많아서 뭐라 딱잘라서 답하기 힙듭니다. 그래서 5 가지로 요약해 보았습니다.


1) /etc/rc.local 

이 파일은 컴퓨터가 시작할때 모든 프로그램들을 시작하고나서 따로 시작하고 싶은 시스템 프로그램이 있을때 씁니다.  보통 간단하게 끝낼수 있는  customized 된 system command 를 씁니다. 사용방법은 그냥 ㅤㅁㅐㅌ 밑줄에 실행 파일 이름을 써주시면 됩니다


2) /etc/init.d/프로그램들

여기는 시스템 서비스(daemon) 로 들어가는 프로그램들을 모아두는 곳입니다. 대부분 여기에 모아놓고 run level 에 따라서 /etc/rc/ rc.1, rc.2, rc.3, rc.4,rc.5 로 가서 적절한 프로그램들을 실해 시킵니다. 여기는 service 나 daemon  전용입니다.


3) /etc/bashrc 

이건 유저들이 bash 를 쓴다고 가정을 할때, 모든 유저들에게 해당하는 부분을 시작하는 겁니다. 예를 들면 라이브러리나 path 설정 같은거요


4) ~/.bashrc

이건 2) 번 과 똑같은거 이지만 개인 유저들에만 적용되는 것입니다. 보통 여기를 젤 많이 건드립니다.


5) 유저 하기 나름


말씀 드렸듯이 이게 linux 의 통상적으로 적용되는 룰 입니다. 보통 시스템 레벨 프로그램은 rc.local 에 가장 많이 넣지만, daemon 으로 만들고 싶으면 /etc/init.d 에 넣고 시간이 걸리더라고 daemon 으로 만드는 방법을 찾아 보시면 됩니다.

그냥 유저 레벨에서 사용하고 싶으시면 ~/.bashrc 에 넣고 하시는게 젤 편하구요.


참고로 명령어 뒤에 &  를 넣으면 background 에서 돌아간다는것도 염두에 두셔야 할겁니다. 왜냐면 순처작으로 script 가 진행이 될때에는 특정 라인의 command 가 끝나지 않으면 다음으로 가지 않을수 도있기 때문입니다.


그리고 ubuntu 가 뭘 어떻게 하는지는 저도 잘 몰겠네요. 말씀 드렸듯이 워낙 할수 있는 방법이 많아서요, source 를 보기 전에는 정확히 말씀 못드리겠네요. 참고로 저는 fedora 광팬입니다 ^^ Redhat 이 돈받기 시작하면서 부터 그냥 쭉 fedora 써 왔거든요


출처 - http://k.daum.net/qna/view.html?category_id=QCE003&qid=3ZwUa&q=%B8%AE%B4%AA%BD%BA+%BD%C3%C0%DB%C7%C1%B7%CE%B1%D7%B7%A5&srchid=NKS3ZwUa






'System > Linux' 카테고리의 다른 글

linux - saslpasswd2  (0) 2014.03.03
linux - cgroups (control groups)  (0) 2014.03.02
linux - sudo  (0) 2014.02.23
linux - /var  (0) 2014.02.23
linux - install problem wine in fedora 17  (0) 2014.02.16
Posted by linuxism
,