本文描述的是在CentOS 7搭建的过程。

创建Unit文件

1
vi /etc/systemd/system/simplehttp.service

文件内容如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[Unit]
Description=My Simple Service
After=network.target

[Service]
Type=simple
User=leon
WorkingDirectory=/home/leon/simplehttpserverdir
ExecStart=/usr/bin/python -m SimpleHTTPServer 8081
ExecStop=/bin/kill `/bin/ps aux | /bin/grep SimpleHTTPServer | /bin/grep -v grep | /usr/bin/awk '{ print $2 }'`
Restart=on-abort

[Install]
WantedBy=multi-user.target

启动SimpleHttp.service

1
2
systemctl daemon-reload
systemctl restart simplehttp.service