[Ubuntu] 시작시 자동 실행 하기
1. 프로파일 수정
vi ~/.profile
작성방법 예시
ex)
$HOME/script1.sh &
(home에 있는 script1.sh를 실행 시켜라)
2. 스크립트 생성 및 수정
<script1.sh> 파일 생성 (vi script.sh)
cd /home/user/위치 && python3 파일.py
--------
안될경우 다른방법
1. 서비스 실행 스크립트 생성
- cd /etc/init.d
- sudo vi script1.sh (스크립트 만들기)
- i (vi 파일 작성 실행 키)
2. startup1.sh라는 파일에 mkdir 명령어를 통해 test1라는 디렉토리를 생성 (시작시 실행 명령)
- #! /bin/sh (sh 형식의 스크립트를 실행 하겠다는 내용)
- mkdir /home/test1
- esc -> :wq (저장 후 종료)
3. 권한 설정
- sudo chmod 755 script1.sh
4. 업데이트
- sudo update-rc.d script1.sh defaults
(2번에서 하고싶은 내용을 적어 주면 바로 실행이 됩니다.)
--------
안될경우 다른방법
- check
sudo systemctl status rc-local
sudo systemctl enable rc-local
sudo systemctl status rc-local
- rc-local.service
sudo vim /etc/systemd/system/rc-local.service
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
- rc.local
sudo vim /etc/rc.local
sudo mkdir /home/ubuntu/Desktop/test1
sleep 5
chmod -R 777 /home/ubuntu/Desktop/test1
exit 0
esc - :wq!
sudo chmod +x /etc/rc.local
sudo systemctl enable rc-local
sudo systemctl start rc-local
sudo systemctl status rc-local
- reboot
sudo shutdown -r now