How to Start/Stop/Restart Services on Alpine Linux

This post will guide you how to start/restart/stop services on your Alpine Linux. How do I enable service when the Alpine Linux starts up.

What is Alpine Linux


Alpine Linux is a Linux distribution based on musl and BusyBox, primarily designed for “power users who appreciate security, simplicity and resource efficiency”. It uses a hardened kernel and compiles all user space binaries as position-independent executables with stack-smashing protection.
Alpine Linux uses OpenRC for its init system.

Start Service on Alpine Linux


If you are using Alpine Linux, and you want to start a service, such as: httpd, you can type the following command:

# /etc/init.d/httpd start

Or

# rc-service httpd start

Stop Service on Alpine Linux


If you want to stop a specific service on your Alpine Linux server, you can use one of the following command:

# /etc/init.d/httpd stop

Or

# rc-service httpd stop

Restart Service on Alpine Linux


If you modified some configuration files (httpd.conf), and then you need to restart the service, such as: httpd, just type the following command:

#/etc/init.d/httpd restart

Or

# rc-service httpd restart

Configure Services to Start Automatically


If you want to enable services when alpine Linux starts up, you can the following command:

# rc-update add <service_name> <runlevel>

Enable httpd service at boot time, type:

#rc-update add httpd boot

Of course, you can also disable service at boot time, just type the following command:

# rc-update del <service_name> <runlevel>
# rc-update del httpd boot

Show List of run levels on Alpine Linux


If you want to show the list of all run levels on your Alpine Linux, type the following command:

# rc-status --list

Outputs:

#rc-status --list
boot
nonetwork
default
sysinit
shutdown

Available Runlevels For Alpine Linux


The available runlevels are:

● default – Used if no runlevel is specified. (This is generally the runlevel you want to add services to.)

● hotplugged

● manual

The special runlevels are:

● sysinit – Brings up any system specific stuff such as /dev, /proc and optionally /sys for Linux based systems. It also mounts /lib/rc/init.d as a ramdisk using tmpfs where available unless / is mounted rw at boot. rc uses /lib/rc/init.d to hold state information about the services it runs. sysinit always runs when the host first starts and should not be run again.

● boot – Generally the only services you should add to the boot runlevel are those which deal with the mounting of filesystems, set the initial state of attached peripherals and logging. Hotplugged services are added to the boot runlevel by the system. All services in the boot and sysinit runlevels are automatically included in all other runlevels except for those listed here.

● single – Stops all services except for those in the sysinit runlevel.

● reboot – Changes to the shutdown runlevel and then reboots the host.

● shutdown – Changes to the shutdown runlevel and then halts the host.

Change to A Differenet Runlevel


If you want to change the current runlevel to another, just use the rc command with a specific runlevel, type:

# rc boot
# rc single

More Information about rc-update/rc-status/rc-service/rc commands


If you want to get more help for those command (rc-update, rc-status, rc-service,rc), just use the following commands:

#rc-update --help
#rc-status --help
#rc-service --help
#rc --help

Outputs:

#rc-update --help
Usage: rc-update [options] add service <runlevel>
rc-update [options] del service <runlevel>
rc-update [options] show

Options: [suChqv]
-s, --stack Stack a runlevel instead of a service
-u, --update Force an update of the dependency tree
-h, --help Display this help output
-C, --nocolor Disable color output
-v, --verbose Run verbosely
-q, --quiet Run quietly

#rc-status --help
Usage: rc-status [options] [runlevel1] [runlevel2] ...

Options: [aclrsuChqv]
-a, --all Show services from all run levels
-c, --crashed Show crashed services
-l, --list Show list of run levels
-r, --runlevel Show the name of the current runlevel
-s, --servicelist Show service list
-u, --unused Show services not assigned to any runlevel
-h, --help Display this help output
-C, --nocolor Disable color output
-v, --verbose Run verbosely
-q, --quiet Run quietly

#rc-service --help

Usage: rc-service [options]

Options: [e:ilr:ChqVv]
-e, --exists <arg> tests if the service exists or not
-i, --ifexists if the service exists then run the command
-l, --list list all available services
-r, --resolve <arg> resolve the service name to an init script
-h, --help Display this help output
-C, --nocolor Disable color output
-V, --version Display software version
-v, --verbose Run verbosely
-q, --quiet Run quietly

#rc --help
Usage: rc [options]

Options: [a:o:s:SChqVv]
-a, --applet <arg> runs the applet specified by the next argument
-o, --override <arg> override the next runlevel to change into
when leaving single user or boot runlevels
-s, --service <arg> runs the service specified with the rest
of the arguments
-S, --sys output the RC system type, if any
-h, --help Display this help output
-C, --nocolor Disable color output
-V, --version Display software version
-v, --verbose Run verbosely
-q, --quiet Run quietly

 

You might also like:

Sidebar



back to top