Hippies

標題: 在 Linux 上 用 C++ 来coding service application [打印本頁]

作者: kevinhu    時間: 2015-12-9 16:33
標題: 在 Linux 上 用 C++ 来coding service application
要在 Linux 上开发 Daemon application 可以参考看看,C++ 来开发。
Linux Daemon Writing Howto


作者: kevinhu    時間: 2015-12-30 18:09
Write Daemon or Service in Linux
作者: kevinhu    時間: 2016-1-4 15:27
本帖最後由 kevinhu 於 2016-1-6 11:53 編輯

Coding 只是完成程序,但是要掛上去還需要寫個Script才行的。
參考網站鏈接
How to Write Linux Init Scripts Based on LSB Init Standard
作者: kevinhu    時間: 2016-1-5 17:27
本帖最後由 kevinhu 於 2016-1-19 15:10 編輯

如果要在開機時能自動啟動的話還必須要先跟系統註冊哦
update-rc.d

底下是實作的參考
Auto-start Checklist for System VThis section is a quick reference to make sure your service is set to automatically start.
Configuration Checklist
  lrwxrwxrwx 1 root root  15 Jul 31 07:09 S02mysql -> ../init.d/serviceNote that you should also see links from directories /etc/rc3.d through /etc/rc5.d; learn more about these numbers when we discuss runlevels.
/etc/inittab
    id:2345:respawn:/bin/sh /path/to/application/startupTest
To test that these are working, you can:



作者: kevinhu    時間: 2016-3-29 11:10
在Linux上目前有3種主要Init System,分別為 SysVinit、systemd及Upstart,依Linux各個分支所選用為主,有關這些的系統演進情況看參考下列的鏈接
淺析 Linux 初始化 init 系統

使用的方法可參考下列的轉貼文:
There are currently 3 main init systems used by linux. A few years ago, there was just one, SysVinit. But SysVinit was seriously lacking in capabilities such as service dependency graphing, so it's been deprecated in most distros by now. Currently most distros are switching to systemd. Though there is also upstart.

But here's the answer to your question for each of the 3 init systems:


SysVinit

SysVinit currently used by Debian and RedHat. Though the next version of RedHat (7) will be using systemd.

The univeral way of enabling SysVinit services on boot is to symlink them in /etc/rc3.d (or /etc/rc2.d). All services can be found in /etc/init.d. Note however that distros will often have their own tool for managing these files, and that tool should be used instead. (Fedora/RedHat has service and chkconfig, ubuntu has update-rc.d)
List services:

ls /etc/init.d/

Start service:

/etc/init.d/{SERVICENAME} start

Stop service:

/etc/init.d/{SERVICENAME} stop

Enable service:

cd /etc/rc3.d
ln -s ../init.d/{SERVICENAME} S95{SERVICENAME}

(the S95 is used to specify order. S01 will start before S02, etc)
Disable service:

rm /etc/rc3.d/*{SERVICENAME}


Systemd

The most notable distribution using systemd is Fedora. Though it is used by many others. Additionally, with Debian having chosen to go with systemd over upstart, it will become the defacto upstart system for most distributions (ubuntu has already announced they will be dropping upstart for systemd).
List services:

systemctl list-unit-files

Start service:

systemctl start {SERVICENAME}

Stop service:

systemctl stop {SERVICENAME}

Enable service:

systemctl enable {SERVICENAME}

Disable service:

systemctl disable {SERVICENAME}


Upstart

Upstart was developed by the Ubuntu folks. But after debian decided to go with systemd, Ubuntu announced they would drop upstart.

Upstart was also briefly used by RedHat, as it is present in RHEL-6, but it is not commonly used.
List services:

initctl list

Start service:

initctl start {SERVICENAME}

Stop service:

initctl stop {SERVICENAME}

Enable service:

2 ways unfortunately:

    There will be a file /etc/default/{SERVICENAME} which contains a line ENABLED=.... Change this line to ENABLED=1.

    There will be a file /etc/init/{SERVICENAME}.override. Make sure it contains start (or is absent entirely), not manual.

Disable service:

echo manual > /etc/init/{SERVICENAME}.override

作者: kevinhu    時間: 2016-4-12 14:23
本帖最後由 kevinhu 於 2016-4-13 00:15 編輯

目前許多Linux的新版本大多轉換使用Systemd來管理service,因此有需要的話還是要了解一下在Systemd的架構及script的編寫方式,相關資料請參考
systemd 說明

一篇國外寫的文章對systemd的使用說明及心得
Getting Started With systemd on Debian Jessie

這裡有一篇指導如何撰寫systemd的service script以及如何由SysV init script 轉換成systemd的unit file,出自於Redhat 的Administrator's Guid
Creating and Modifying systemd Unit Files





歡迎光臨 Hippies (http://bbs.hippies.tw/) Powered by Discuz! X3.2