Code Monkey home page Code Monkey logo

new-service's Introduction

Our fork from: https://github.com/wyhasany/sample-service-script/

################################# There info was:

Install new service debianoids

Note:

You can proberly acheive the same thing that this project tries to acheive by using the: MetaInit package in debian: (https://wiki.debian.org/MetaInit)

Anyway take a look at LSB init scripts for more information.

Usage

Copy to /etc/init.d:

# replace "$YOUR_SERVICE_NAME" with your service's name (whenever it's not enough obvious)
cp "service.sh" "/etc/init.d/$YOUR_SERVICE_NAME"
chmod +x /etc/init.d/$YOUR_SERVICE_NAME

Edit the script and replace following tokens:

  • <NAME> = $YOUR_SERVICE_NAME
  • <DESCRIPTION> = Describe your service here (be concise)
  • Feel free to modify the LSB header, I've made default choices you may not agree with
  • <COMMAND> = Command to start your server (for example /home/myuser/.dropbox-dist/dropboxd)
  • <USER> = Login of the system user the script should be run as (for example myuser)

Start and test your service:

service $YOUR_SERVICE_NAME start
service $YOUR_SERVICE_NAME stop

Install service to be run at boot-time:

update-rc.d $YOUR_SERVICE_NAME defaults

For rpm based distributions such as CentOS or Red Hat, you can use

chkconfig $YOUR_SERVICE_NAME --add

If you want to see which runlevel your script will run in

chkconfig $YOUR_SERVICE_NAME --list

Enjoy

Uninstall

The service can uninstall itself with service $NAME uninstall. Yes, that's very easy, therefore a bit dangerous. But as it's an auto-generated script, you can bring it back very easily. I use it for tests and often install/uninstall, that's why I've put that here.

Don't want it? Remove lines 56-58 of the service's script.

Logs?

Your service will log its output to /var/log/$NAME.log. Don't forget to setup a logrotate :)

I'm noob and/or lazy

Yep, I'm lazy too. But still, I've written a script to automate this :)

wget 'https://raw.githubusercontent.com/jasonblewis/sample-service-script/master/new-service.sh' && bash new-service.sh

In this script I will download service.sh into a tempfile, replace some tokens, and then show you commands you should run as superuser.

If you feel confident enough with my script, you can sudo the script directly:

wget 'https://raw.githubusercontent.com/jasonblewis/sample-service-script/master/new-service.sh' && sudo bash new-service.sh

Note: the cool hipsterish curl $URL | bash won't work here, I don't really want to check why.

The script works offline so you can clone this repository then you can upload this script on your server and run it directly:

sudo bash new-service.sh

The script also handle parameters as showed below:

sudo bash new-service.sh "service_name" "description" "command to execute" "user which should run command"

Demo

Creating the service:

service-create

Looking at service files (logs, pid):

service-files

Uninstalling service:

service-uninstall

new-service's People

Contributors

naholyr avatar stephdl avatar jasonblewis avatar sinamomken avatar mklarsen avatar molikuner avatar dav3xor avatar dominiquecomte avatar reduardo7 avatar wyhasany avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.