Centos 7 Script to install as Linux Service

Posted in :

在 CentOS 裡新增一個 script 為 service 的解法,和在 Ubuntu 上的有點像,但是需要多一個步驟,去多寫一個 your-service-name.service 的檔案。

先看之前的解法:新增指令在Ubuntu 開機時執行
http://stackoverflow.max-everyday.com/2017/02/ubuntu-boot-command/

Step 1:

和 Ubuntu 一樣,先到 /etc/init.d/ 目錄裡寫一個 script, ex: max_mdm

 

Step 2:

到 /etc/rc5.d/ 目錄裡執行 ln -s /etc/init.d/max_mdm S99max_mdm

 

Step 3: 

Create the following file:

/usr/lib/systemd/system/max_mdm.service

[Unit]
Description=My Script

[Service]
Type=forking
ExecStart=/usr/bin/myscript

  • Reload the systemd service files: systemctl daemon-reload
  • Check that it is working with systemctl start my

也可以直接執行

service max_mdm start

 

 

相關文章:

新增指令在Ubuntu 開機時執行
http://stackoverflow.max-everyday.com/2017/02/ubuntu-boot-command/

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *