# 製作linux開機自動啟動 ### 一、Ubuntu systemctl service 1. 建立檔案: - sudo **vim** docker-compose-aiot.service ``` 範例: [Unit] Description=Docker Compose Application Service Requires=docker.service After=docker.service [Service] Type=sample Restart=always RestartSec=3 StartLimitIntervalSec=1200 StartLimitBurst=10 TimeoutStartSec=1200 WorkingDirectory=/home/twibm/git/iot_gw_web/docker ExecStart=/usr/local/bin/docker-compose -f iot_gw_all.yaml up ExecStop=/usr/local/bin/docker-compose -f iot_gw_all.yaml down [Install] WantedBy=multi-user.target ``` 3. 複製到systemctl.service目錄 (/etc/systemd/system): - sudo **cp** docker-compose-aiot.service **/etc/systemd/system** 3. 註冊service - sudo systemctl **install** docker-compose-aiot.service 4. 啟用serice - sudo systemctl **enable** docker-compose-aiot.service 5. 狀態service - sudo systemctl **stats** docker-compose-aiot.service 7. 停止service - sudo systemctl **stop** docker-compose-aiot.service 9. 解除service - sudo systemctl **disable** docker-compose-aiot.service ### 二、supervisor 1. 安裝 - sudo apt-get install supervisor 2. 建立檔案: - sudo **vim /etc/supervisor/conf.d/updatemeter.conf** ``` 範例: [program:updatemeter] command=/usr/bin/python3 run_proj.py user=root directory=/home/twibm/git/iot_mbus/iot_modbus autostart=true autorestart=true stopwaitsecs=20 ``` 3. 重載 * sudo supervisorctl **reload** ``` 會自動將 con.d 底下所有 *.conf files 皆檢查並自動載入執行 ``` 4. 啟動 * sudo supervisorctl **start updatemeter** 5. 關閉 * sudo supervisorctl **stop updatemeter** 6. 狀態 * sudo supervisorctl **status updatemeter** ###### tags: `主機設定`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up