vim /lib/systemd/system/jkb.servcie


[Unit]

Description=jkb

After=network.target


[Service]

Type=forking

#PIDFile=/root/jkb_agent/jkb.pid

ExecStart=/usr/bin/sh /root/jkb_agent/start.sh

ExecStop=/usr/bin/sh /root/jkb_agent/stop.sh

PrivateTmp=true


[Install]

WantedBy=multi-user.target


systemctl daemon-reload

systemctl enable jkb.service

service jkb status

Redirecting to /bin/systemctl status  jkb.service

jkb.service - jkb

   Loaded: loaded (/usr/lib/systemd/system/jkb.service; enabled)

   Active: active (running) since 五 2016-01-08 16:26:58 HKT; 2min 27s ago

  Process: 26537 ExecStop=/usr/bin/sh /root/jkb_agent/stop.sh (code=exited, status=0/SUCCESS)

  Process: 26617 ExecStart=/usr/bin/sh /root/jkb_agent/start.sh (code=exited, status=0/SUCCESS)

 Main PID: 26621 (python)

   CGroup: /system.slice/jkb.service

           ├─26621 python jkbMaster.py start

           ├─26694 /usr/bin/python /root/jkb_agent/jkbAgent.py 26621

           ├─28836 snmpwalk -v 3 -u -a MD5 -A -l authNoPriv 45.116.147.202:161 ssCpuRawUser

           ├─28843 snmpwalk -v 3 -u -a MD5 -A -l authNoPriv 103.56.195.9:161 ssCpuRawNice

           ├─28844 snmpwalk -v 3 -u -a MD5 -A -l authNoPriv 103.56.195.10:161 ssCpuRawUser

           ├─28852 snmpwalk -v 3 -u -a MD5 -A -l authNoPriv 103.56.195.23:161 ssCpuRawNice

           ├─28853 snmpwalk -v 3 -u -a MD5 -A -l authNoPriv 103.56.195.4:161 ssCpuRawNice

           ├─28854 snmpwalk -v 3 -u -a MD5 -A -l authNoPriv 103.56.195.12:161 ssCpuRawUser

           ├─28855 snmpwalk -v 3 -u -a MD5 -A -l authNoPriv 45.116.147.210:161 ssCpuRawUser

           ├─28865 snmpwalk -v 3 -u -a MD5 -A -l authNoPriv 103.56.195.2:161 ssCpuRawNice

           ├─28870 snmpwalk -v 3 -u -a MD5 -A -l authNoPriv 103.56.195.22:161 ssCpuRawNice

           ├─28872 snmpwalk -v 3 -u -a MD5 -A -l authNoPriv 103.56.195.13:161 ifMtu

           ├─28874 snmpwalk -v 3 -u -a MD5 -A -l authNoPriv 45.116.147.178:161 ssCpuRawUser

           ├─28877 snmpwalk -v 3 -u -a MD5 -A -l authNoPriv 45.116.147.186:161 ssCpuRawUser

           ├─28891 snmpwalk -v 3 -u -a MD5 -A -l authNoPriv 103.56.195.21:161 ssCpuRawUser

           ├─28899 snmpwalk -v 3 -u -a MD5 -A -l authNoPriv 103.56.195.11:161 ssCpuRawUser

           ├─28904 snmpwalk -v 3 -u -a MD5 -A -l authNoPriv 45.116.147.218:161 ssCpuRawNice

           ├─28905 snmpwalk -v 3 -u -a MD5 -A -l authNoPriv 103.56.193.16:161 ssCpuRawUser

           ├─28906 snmpwalk -v 3 -u -a MD5 -A -l authNoPriv 45.116.147.162:161 ssCpuRawUser

           ├─28915 snmpwalk -v 3 -u -a MD5 -A -l authNoPriv 103.56.195.15:161 ssCpuRawNice

           ├─28917 snmpwalk -v 3 -u -a MD5 -A -l authNoPriv 103.56.195.17:161 ssCpuRawUser

           ├─28918 snmpwalk -v 3 -u -a MD5 -A -l authNoPriv 103.56.195.8:161 ssCpuRawUser

           ├─28919 snmpwalk -v 3 -u -a MD5 -A -l authNoPriv 103.56.195.20:161 ssCpuRawSystem

           └─28928 snmpwalk -v 3 -u -a MD5 -A -l authNoPriv 103.56.195.16:161 ssCpuRawUser

1月 08 16:26:58 fortress-new systemd[1]: Started jkb.


PS:执行程序jkb_agent/start.sh和stop.sh最好不要放/tmp目录,systemctl无法读取该目录:

[root@fortress-new system]# systemctl status jkb.service 

jkb.service - jkb

   Loaded: loaded (/usr/lib/systemd/system/jkb.service; enabled)

   Active: failed (Result: exit-code) since 四 2016-01-07 17:58:11 HKT; 22h ago

  Process: 8904 ExecStart=/tmp/jkb_agent/start.sh (code=exited, status=203/EXEC)


1月 07 17:58:11 fortress-new systemd[8904]: Failed at step EXEC spawning /tmp/jkb_agent/start.sh: No such file or directory

1月 07 17:58:11 fortress-new systemd[1]: jkb.service: control process exited, code=exited status=203

1月 07 17:58:11 fortress-new systemd[1]: Failed to start jkb.

1月 07 17:58:11 fortress-new systemd[1]: Unit jkb.service entered failed state.