自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Ubuntu Service腳本編寫示例

系統(tǒng) Linux
使用 Linux 時(shí)經(jīng)常用到 ` service mysql restart ` 等命令, 方便進(jìn)行服務(wù)的操作, 具體的服務(wù)是怎么寫的呢,通過以下示例將了解以下內(nèi)容。

[[422653]]

使用 Linux 時(shí)經(jīng)常用到 ` service mysql restart ` 等命令, 方便進(jìn)行服務(wù)的操作, 具體的服務(wù)是怎么寫的呢,通過以下示例將了解以下內(nèi)容:

  • 如何寫一個(gè)簡單的服務(wù)
  • 服務(wù)異常關(guān)閉時(shí)能自動開啟配置

簡單的示例

nano /lib/systemd/system/xx.service 

  1. [Unit] 
  2. Description=Check GPU INFO by chenwei   # 服務(wù)描述 
  3. Wants=network-online.target             # 服務(wù)依賴于網(wǎng)絡(luò) 
  4. After=network-online.target 
  5.  
  6. [Service] 
  7. Type=simple 
  8. ExecStart=/root/shell/agent/chkgpu      # 服務(wù)開啟時(shí)執(zhí)行腳本 
  9. ExecReload=/bin/kill -HUP $MAINPID      # 服務(wù)重新加載時(shí)執(zhí)行腳本 
  10. RestartSec=5s                           # 自動啟動間隔時(shí)間 
  11. Restart=on-failure                      # 在什么情況下會自動重啟 
  12.  
  13. [Install] 
  14. WantedBy=multi-user.target   
  15.  
  16. [Unit] 
  17. Description=Advanced key-value store 
  18. After=network.target 
  19.  
  20. [Service] 
  21. Type=forking 
  22. ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf 
  23. ExecStop=/bin/kill -s TERM $MAINPID 
  24. PIDFile=/var/run/redis_6379.pid 
  25. Restart=always 
  26. RestartSec=5s 
  27. Restart=on-failure 
  28.  
  29.  
  30. [Install] 
  31. WantedBy=multi-user.target 
  32. Alias=redis.service 

nginx 示例 

  1. [Unit] 
  2. Description=A high performance web server and a reverse proxy server 
  3. After=network.target 
  4.  
  5. [Service] 
  6. Type=forking 
  7. PIDFile=/var/run/nginx.pid 
  8. #ExecStartPre=/usr/local/nginx/sbin/nginx  
  9. ExecStart=/usr/sbin/nginx  
  10. ExecReload=/usr/sbin/nginx -s reload 
  11. ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid 
  12. TimeoutStopSec=5 
  13. KillMode=mixed 
  14.  
  15. [Install] 
  16. WantedBy=multi-user.target 

常用命令 

  1. systemctl enable --now nginx.service  # 立刻開啟并開機(jī)啟動 
  2.  
  3. systemctl daemon-reload #重新加載 
  4.  
  5. systemctl enable nginx.service #開機(jī)時(shí)啟動 
  6. systemctl disable nginx.service #開機(jī)時(shí)禁用 
  7. systemctl list-unit-files|grep enabled #已啟動服務(wù)列表 
  8. systemctl --failed  #啟動失敗服務(wù)列表 

wssh 

  1. file=/lib/systemd/system/myssh.service mv $file $file.bak cat «EOF »$file 
  2.  
  3. [Unit] Description=Web SSH server by chenwei. pip install webssh Wants=network-online.target 
  4. After=network-online.target 
  5.  
  6. [Service] Type=simple ExecStart=wssh ExecReload=/bin/kill -HUP $MAINPID 
  7. RestartSec=5s 
  8. Restart=on-failure 
  9.  
  10. [Install] WantedBy=multi-user.target 
  11.  
  12. EOF cat $file 

issh 

  1. file=/usr/bin/issh 
  2. mv $file $file.bak 
  3. cat <<EOF >>$file 
  4. #!/bin/bash 
  5. wssh 
  6. autossh -M 10111 -NR 0.0.0.0:11111:localhost:22 pc@1.10sh.cn 
  7.  
  8.  
  9. EOF 
  10. cat $file 
  11.  
  12. chmod +x  $file 
  13.  
  14. file=/lib/systemd/system/issh.service 
  15. mv $file $file.bak 
  16.  
  17. cat <<EOF >>$file 
  18.   
  19. [Unit] 
  20. Description=autossh shell to connect to my server by chenwei.  #sudo apt  install autossh 
  21.  
  22. Wants=network-online.target 
  23. After=network-online.target 
  24.  
  25. [Service] 
  26. Type=simple 
  27. ExecStart=/usr/bin/issh 
  28. ExecReload=/bin/kill -HUP 
  29. RestartSec=5s 
  30. Restart=on-failure 
  31.  
  32. [Install] 
  33. WantedBy=multi-user.target 
  34.  
  35.  
  36. EOF 
  37. cat $file 
  38.  
  39.  
  40. systemctl enable --now issh.service 
  41.  
  42. systemctl status issh.service 

pweb

使用python 啟動一個(gè)簡單的 http 文件服務(wù)。 

  1. sudo -i 
  2.  
  3.  
  4. file=/home/pweb.sh 
  5. mv $file $file.bak 
  6. cat <<EOF >>$file 
  7.  
  8.  
  9. #!/bin/bash 
  10. python3 -m http.server 
  11.  
  12. EOF 
  13. cat $file 
  14.  
  15. chmod +x  $file 
  16.  
  17. file=/lib/systemd/system/pweb.service 
  18. mv $file $file.bak 
  19. cat <<EOF >>$file 
  20.  
  21.   
  22. [Unit] 
  23. Description=Simple python pweb by chenwei. 
  24.  
  25. Wants=network-online.target 
  26. After=network-online.target 
  27.  
  28. [Service] 
  29. Type=simple 
  30. ExecStart=/home/pweb.sh 
  31. ExecReload=/bin/kill -HUP 
  32. RestartSec=5s 
  33. Restart=on-failure 
  34.  
  35. [Install] 
  36. WantedBy=multi-user.target 
  37.  
  38.  
  39. EOF 
  40. cat $file 
  41.  
  42. systemctl enable --now pweb.service 
  43.  
  44. systemctl status pweb.service 

 

 

責(zé)任編輯:未麗燕 來源: 今日頭條
相關(guān)推薦

2010-04-19 11:21:39

Oracle視圖

2009-12-08 17:16:37

WCF Web Ser

2012-04-26 14:02:58

ibmdw

2022-06-21 09:26:21

Shell腳本JavaScript

2009-07-14 15:27:17

Jython腳本示例

2023-05-20 17:45:25

LinuxShell

2009-10-26 12:17:03

linux腳本編寫

2011-03-01 09:30:27

LinuxScreenletPython

2021-07-19 15:12:21

Python編程語言

2024-01-15 08:00:00

開發(fā)API文檔集成

2017-04-13 10:51:17

Bash建議

2022-06-27 09:00:55

SwiftGit Hooks

2023-06-28 00:05:44

人工智能聊天機(jī)器人ChatGPT

2017-08-11 17:20:07

LinuxShell

2010-09-09 11:16:06

CSS交互

2021-02-07 13:00:40

GIMP開源圖像編輯器

2022-01-04 15:35:51

鴻蒙HarmonyOS應(yīng)用

2010-01-08 14:02:25

Ubuntu Bery

2010-06-09 17:11:33

Ubuntu mrtg

2010-06-07 17:18:54

Ubuntu mrtg
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號