I’ve noticed that there are a lot of faulty or non properly working start/stop scripts out there in the wild. That’s why I made the decision to build some example or default services for the common distributions (and even operating systems, like Windows). In this case our example service is Python’s SimpleHTTPServer
which starts a web server on port 80 and serves the current working directory to the web server. The server can be easily executed by:
$ python -m SimpleHTTPServer 8000
(Caution: this command will probably serve the root directory of your machine. Make sure to stop the service again!)
Debian and Ubuntu (sysvinit)
- Create an user for the desired service
- Ensure the created user has full access to the binary you want to set up:
/usr/bin/python
- Copy the following script (as root) to
/etc/init.d/
:
wget https://raw.github.com/frdmn/service-daemons/master/debian -O /etc/init.d/example
- Adjust the variables:
sudo vi /etc/init.d/example
- Make sure the script is executable:
chmod +x /etc/init.d/example
- Enable the daemon with:
update-rc.d example defaults
- Start the service with:
service example start
Ubuntu (upstart)
- Create an user for the desired service
- Ensure the created user has full access to the binary you want to set up:
/usr/bin/python
- Copy the following script to
/etc/init/
:
sudo wget https://raw.github.com/frdmn/service-daemons/master/ubuntu -O /etc/init/example.conf
- Adjust the variables:
sudo vi /etc/init/example.conf
- Start the service with:
sudo start example
CentOS 6 (sysvinit)
- Create an user for the desired service
- Ensure the created user has full access to the binary you want to set up:
/usr/bin/python
- Copy the following script (as root) to
/etc/init.d/
:
wget https://raw.github.com/frdmn/service-daemons/master/centos -O /etc/init.d/example
- Adjust the variables (as root):
vi /etc/init.d/example
- Make sure the script is marked as executable:
chmod +x /etc/init.d/example
- Enable the config in in runlevels 2, 3, 4, and 5:
chkconfig example on
- Start the service with:
service example start
Arch Linux (systemd)
- Create an user for the desired service
- Ensure the created user has full access to the binary you want to set up:
/usr/bin/python
- Copy the following script (as root) to
/etc/systemd/system/
:
wget https://raw.github.com/frdmn/service-daemons/master/arch -O /etc/systemd/system/example.service
- Adjust the variables (as root):
/etc/systemd/system/example.service
- Make sure the script is executable:
chmod +x /etc/systemd/system/example.service
- Enable the script on boot with:
systemctl enable example
- To start the script:
systemctl start example
Gentoo (runscript)
- Create an user for the desired service
- Ensure the created user has full access to the binary you want to set up:
/usr/bin/python
- Copy the following script (as root) to
/etc/init.d/
:
wget https://raw.github.com/frdmn/service-daemons/master/gentoo-script -O /etc/init.d/example
- Copy the following configuration file (as root) to
/etc/conf.d/
:
wget https://raw.github.com/frdmn/service-daemons/master/gentoo-conf -O /etc/conf.d/example
- Make those files executable:
chmod +x /etc/init.d/example /etc/conf.d/example
- Load the deamon:
rc-update add etherpad-lite default
- Start the deamon with:
rc-service etherpad-lite start
Mac OS X (launchd)
Note: For some reasons the SimpleHTTPServer python module didn’t work via launchd
, so i included this tiny web server python script in the repo.
- Create an user for the desired service
- Create a log folder for the service:
mkdir /var/log/example
- Ensure the created user has full access to the binary you want to set up:
/usr/bin/python
- Copy the following script (as root) to /Library/LaunchDaemons/:
wget https://raw.github.com/frdmn/service-daemons/master/macosx -O /Library/LaunchDaemons/mn.frd.example.plist
- Copy the python script (as root) to /tmp/:
wget https://raw.github.com/frdmn/service-daemons/master/macosx-httpd.py -O /tmp/httpd.py
- Launch the daemon with:
sudo launchctl load /Library/LaunchDaemons/mn.frd.example.plist
Windows (nssm)
- Download and install
nssm
:
non sucking service manager - Move it into your
%PATH%
- Open an administrative terminal window
- Load the service:
nssm install "C:/Python27/python" -m SimpleHTTPServer 8000 - Reboot your machine
Please let me know in case you found some typos or errors above. You can also fork the repo and send a pull request via GitHub if you have some improvements for the start/stop daemons.