Difference between revisions of "Linux: file /etc/rc.local"

From OnnoWiki
Jump to navigation Jump to search
 
Line 41: Line 41:
 
  sudo systemctl status rc-local
 
  sudo systemctl status rc-local
 
  sudo nano /etc/systemd/system/rc-local.service
 
  sudo nano /etc/systemd/system/rc-local.service
 +
 +
Isi dengan,
  
 
  [Unit]
 
  [Unit]
Line 56: Line 58:
 
  [Install]
 
  [Install]
 
   WantedBy=multi-user.target
 
   WantedBy=multi-user.target
 +
 +
Edit /etc/rc.local
  
 
  vi /etc/rc.local
 
  vi /etc/rc.local
 +
 +
 +
Masukan script yang ingin di jalankan sebelum "exit 0" di /etc/rc.local Sesuaikan dengan keterangan di atas.
 +
Lakukan perintah di bawah ini,
  
 
  sudo chmod +x /etc/rc.local
 
  sudo chmod +x /etc/rc.local

Latest revision as of 09:53, 24 January 2024

Di ubuntu baru tampaknya /etc/rc.local di buang ..

Cek

Untuk mencek apakah /etc/rc.local akan di eksekusi

sudo systemctl edit --full rc-local

Akan keluar, antara lain

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.

Artinya kalau ada /etc/rc.local akan di eksekusi kalau di ijinkan.

Buat /etc/rc.local

touch /etc/rc.local
chmod +x /etc/rc.local

Isi /etc/rc.local

Isi dengan

#!/bin/sh
#atau
#!/bin/bash
# script/program yang mau jalankan, contoh
/usr/bin/python3 /home/onno/program.py &
exit 0


entry /usr/bin/python3 dst bisa diubah sesuai yang kita mau. pastikan ada #!/bin/sh atau #!/bin/bash

Alternatif Lain

sudo systemctl status rc-local
sudo nano /etc/systemd/system/rc-local.service

Isi dengan,

[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

Edit /etc/rc.local

vi /etc/rc.local


Masukan script yang ingin di jalankan sebelum "exit 0" di /etc/rc.local Sesuaikan dengan keterangan di atas. Lakukan perintah di bawah ini,

sudo chmod +x /etc/rc.local
sudo systemctl enable rc-local
sudo systemctl start rc-local.service
sudo systemctl status rc-local.service