Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 10개 있습니다.)

라즈베리 파이 - (윈도우의 NT 서비스처럼) 부팅 시 시작하는 프로그램 설정

부팅 시 자동으로 (로그인이 없는 상태에서도) 시작하는 프로그램은 "/etc/systemd/system"에 등록하면 됩니다.

가령 shell script인 경우 my_script.service와 같은 이름으로 파일을 만들어,

$ cd /etc/systemd/system/
$ sudo nano my_script.service

다음과 같은 내용으로 채워주면 됩니다.

[Unit]
Description=My Shell Script

[Service]
Type=oneshot
ExecStart=/share/myshell.sh
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

위의 my_script.service 파일은 "ExecStart"를 통해 /share/myshell.sh 쉘 스크립트를 실행하는 역할을 합니다.




또는 fork를 수행하는 프로그램은 이렇게 설정하면 됩니다.

[Unit]
Description=native exec
After=my_script.service

[Service]
Type=forking
ExecStart=/share/test.out

[Install]
WantedBy=multi-user.target

게다가 위의 설정은 my_script.service에 대한 의존성을 가지기 때문에 해당 서비스가 실행한 이후에 /share/test.out 프로그램을 수행하게 됩니다.

이렇게 보면, 윈도우의 NT 서비스보다 개발 및 관리가 꽤나 쉽습니다. ^^




"/etc/systemd/system"에 서비스 파일을 등록했으면 이제 변경 사항을 반영 후,

$ sudo systemctl daemon-reload

새롭게 등록한 서비스를 다음과 같이 "start" 옵션으로 시작할 수 있습니다.

$ sudo systemctl start my_script

# 위와 같이 실행하면 ExecStart에 지정한 프로그램이 실행
# 반면 ExceStop 설정을 추가하면 systemctl stop 명령 시 실행됩니다.

또는 부팅 시 활성화는 "enable" 옵션으로 설정할 수 있습니다.

$ sudo systemctl enable my_script

# 반대로 부팅 시 활성화를 제거하고 싶다면 enable을 disable로 변경해서 실행

# 필요 없어진 서비스는 rm 명령어를 이용해 삭제
# sudo rm /etc/systemd/system/my_script.service

부팅 시 실행하라고 지정한 경우 오류 발생 유무를 알기 어려운데 이럴 때는 "systemctl status" 명령어를 이용해 부팅 당시의 상황을 확인할 수 있습니다.

$ sudo systemctl status my_script

프로그램이 실행 중인지는 대략 다음과 같이 확인할 수 있고,

$ ps -aux | grep "test"
root       490  0.0  0.5  39304  2312 ?        Ssl  12:05   0:00 /share/test.out
pi         821  0.0  0.4   4768  1884 pts/0    S+   12:08   0:00 grep --color=auto test

두 번째 칼럼의 값이 process id이므로 kill 명령어에 전달해 강제로 종료하는 것도 가능합니다.

$ sudo kill -9 490

$ ps -aux | grep "test"
pi         834  0.0  0.4   4768  1936 pts/0    S+   12:10   0:00 grep --color=auto test



윈도우즈 사용자를 위한 라즈베리 파이 제로 W 모델을 설정하는 방법
; https://www.sysnet.pe.kr/2/0/11372

Raspberry Pi Zero(OTG)를 다른 컴퓨터에 연결해 가상 이더넷 카드로 쓰는 방법
; https://www.sysnet.pe.kr/2/0/11353

Raspberry Pi Zero(OTG)를 다른 컴퓨터에 연결해 가상 키보드로 쓰는 방법
; https://www.sysnet.pe.kr/2/0/11354

Raspberry Pi Zero(OTG)를 다른 컴퓨터에 연결해 가상 마우스로 쓰는 방법
; https://www.sysnet.pe.kr/2/0/11355

Raspberry Pi Zero(OTG)를 다른 컴퓨터에 연결해 가상 마우스 + 키보드로 쓰는 방법
; https://www.sysnet.pe.kr/2/0/11356

Raspberry Pi Zero(OTG)를 다른 컴퓨터에 연결해 가상 마우스로 쓰는 방법 (절대 좌표)
; https://www.sysnet.pe.kr/2/0/11364

Raspberry Pi Zero(OTG)를 다른 컴퓨터에 연결해 가상 키보드 및 마우스로 쓰는 방법 (절대 좌표, 상대 좌표, 휠)
; https://www.sysnet.pe.kr/2/0/11369

라즈베리 파이 용 C++ 프로젝트에 SSL Socket 적용
; https://www.sysnet.pe.kr/2/0/11411

Raspberry Pi/Windows 다중 플랫폼 지원 컴파일 관련 오류 기록
; https://www.sysnet.pe.kr/2/0/11373

Linux 3: 라즈베리 파이 - (윈도우의 NT 서비스처럼) 부팅 시 시작하는 프로그램 설정
; https://www.sysnet.pe.kr/2/0/11374


[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 8/9/2018]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 



2022-04-22 05시01분
Ubuntu 22.04 WSL 버전부터 /etc/wsl.conf에 다음의 설정으로 ssytemd 사용이 가능하다고 합니다. ^^

[boot]
command = /usr/libexec/wsl-systemd
정성태

... 106  107  108  [109]  110  111  112  113  114  115  116  117  118  119  120  ...
NoWriterDateCnt.TitleFile(s)
11232정성태6/28/201719578Windows: 144. Windows Server 2016에 Windows Identity Extensions을 설치하는 방법
11231정성태6/28/201719519디버깅 기술: 86. windbg의 mscordacwks DLL 로드 문제 - 세 번째 이야기 [1]
11230정성태6/28/201718926제니퍼 .NET: 26. 제니퍼 닷넷 적용 사례 (6) - 잦은 Recycle 문제
11229정성태6/27/201720316오류 유형: 402. Windows Server Backup 관리 콘솔이 없어진 경우
11228정성태6/26/201717461개발 환경 구성: 320. Visual Basic .NET 프로젝트에서 내장 Manifest 자원을 EXE 파일로부터 제거하는 방법파일 다운로드1
11227정성태6/19/201725880개발 환경 구성: 319. windbg에서 python 스크립트 실행하는 방법 - pykd [6]
11226정성태6/19/201717014오류 유형: 401. Microsoft Edge를 실행했는데 입력 반응이 없는 경우
11225정성태6/19/201716256오류 유형: 400. Outlook - The required file ExSec32.dll cannot be found in your path. Install Microsoft Outlook again.
11224정성태6/13/201718750.NET Framework: 661. Json.NET의 DeserializeObject 수행 시 속성 이름을 동적으로 바꾸는 방법파일 다운로드1
11223정성태6/12/201717685개발 환경 구성: 318. WCF Service Application과 WCFTestClient.exe
11222정성태6/10/201721836오류 유형: 399. WCF - A property with the name 'UriTemplateMatchResults' already exists.파일 다운로드1
11221정성태6/10/201718891오류 유형: 398. Fakes - Assembly 'Jennifer5.Fakes' with identity '[...].Fakes, [...]' uses '[...]' which has a higher version than referenced assembly '[...]' with identity '[...]'
11220정성태6/10/201723698.NET Framework: 660. Shallow Copy와 Deep Copy [1]파일 다운로드2
11219정성태6/7/201718829.NET Framework: 659. 닷넷 - TypeForwardedFrom / TypeForwardedTo 특성의 사용법
11218정성태6/1/201721762개발 환경 구성: 317. Hyper-V 내의 VM에서 다시 Hyper-V를 설치: Nested Virtualization
11217정성태6/1/201717911오류 유형: 397. initerrlog: Could not open error log file 'C:\...\MSSQL12.MSSQLSERVER\MSSQL\Log\ERRORLOG'
11216정성태6/1/201719610오류 유형: 396. Activation context generation failed
11215정성태6/1/201721261오류 유형: 395. 관리 콘솔을 실행하면 "This app has been blocked for your protection" 오류 발생 [1]
11214정성태6/1/201718641오류 유형: 394. MSDTC 서비스 시작 시 -1073737712(0xC0001010) 오류와 함께 종료되는 문제 [1]
11213정성태5/26/201724025오류 유형: 393. TFS - The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
11212정성태5/26/201723285오류 유형: 392. Windows Server 2016에 KB4019472 업데이트가 실패하는 경우
11211정성태5/26/201722140오류 유형: 391. BeginInvoke에 전달한 람다 함수에 CS1660 에러가 발생하는 경우
11210정성태5/25/201722456기타: 65. ActiveX 없는 전자 메일에 사용된 "개인정보 보호를 위해 암호화된 보안메일"의 암호화 방법
11209정성태5/25/201770083Windows: 143. Windows 10의 Recovery 파티션을 삭제 및 새로 생성하는 방법 [16]
11208정성태5/25/201728840오류 유형: 390. diskpart의 set id 명령어에서 "The specified type is not in the correct format." 오류 발생
11207정성태5/24/201729678Windows: 142. Windows 10의 복구 콘솔로 부팅하는 방법
... 106  107  108  [109]  110  111  112  113  114  115  116  117  118  119  120  ...