Skip to content
Projects

fhd/init-script-template

View on GitHub

fhd/init-script-template has 1,090 GitHub stars and 308 forks. GitHot measured 0 stars in 24 hours. Last checked 2026-11-09 10:23 UTC. Last push 2022-02-11.

How these counts are measured

A template for simple System V init scripts

Measured star growth

in 24h
0
in 7 days
Collecting history
in 15 days
Collecting history
in 1 month
Collecting history

Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.

README.md

Original

System V init script template

A simple template for init scripts that provide the start, stop, restart and status commands.

Handy for Node.js apps and everything else that runs itself.

Getting started

Copy template to /etc/init.d and rename it to something meaningful. Then edit the script and enter that name after Provides: (between ### BEGIN INIT INFO and ### END INIT INFO).

Now set the following three variables in the script:

dir

The working directory of your process.

cmd

The command line to start the process.

user

The user that should execute the command (optional). If not set, the command will be called as root (via sudo ...).

Here's an example for an app called algorithms:

dir="/var/apps/algorithms"
cmd="node server.js"
user="node"

Script usage

Start

Starts the app.

/etc/init.d/algorithms start

Stop

Stops the app.

/etc/init.d/algorithms stop

Restart

Restarts the app.

/etc/init.d/algorithms restart

Status

Tells you whether the app is running. Exits with 0 if it is and 1 otherwise.

/etc/init.d/algorithms status

Logging

By default, standard output goes to /var/log/scriptname.log and error output to /var/log/scriptname.err. If you're not happy with that, change the variables stdout_log and stderr_log.

License

Copyright (C) 2012-2014 Felix H. Dahlke

This is open source software, licensed under the MIT License. See the file LICENSE for details.

Explore related projects