When the systemboots to achieveparallelstarting of services;withsocket/D-Bus activationtechniquesstart the servicein order toreducestartuptime,systemdgoalis:start a processlessas possible;moreprocessstarted in parallelas possible;

On–demandactivationprocessSystemd providesability to startondemand,onlywhenaservice is requested by real time whenstartingit.Whentheserviceended,systemdcanshutit down,wait for the next time youneed to startitagain.

Systemusing the featuresof the Linux kernelwhichCGroup tocompleteprocesstrackingtasks.When you stop the service,byquerying the CGroup,systemd can besure to findalltherelevantprocesses,so as to cleanout of service;

Logservice:withsystemdlogservicejournald,thelogserviceisdesigned to overcometheshortcomings of the existingsyslogservice.

Thebasicconcepts of System

Concept:

Systeminitializationneeds to be doneverymuch.Need to start the spoolerservice,start the SSHD serviceconfigurationneeds to be done,such asmounting the filesystem.Systemdeachstepinthisprocess is abstractedintoahive,theunit.Aservicecan beconsidered to beahive;amountpointisahive;aswappartitionconfigurationisaconfigurationelement, and so on.Systemdhiveinto a number of differenttypes.However,systemdis growingrapidly,increasingnewfeatures.Configuringelementtypesmaycontinue toincreasein the nearfuture.

Socket:thistype of hivepackagesystemandasocketin the Internet.Now,systemdsupportsstreaming,packetsandcontinuousforAF_INET,AF_INET6,AF_UNIX socket.Eachsocketconfigurationprofiles with the unithasacorrespondingunit. The correspondingservicein the first“connected“into the socket, itwillstart(for example:nscd.Socketnewconnectionwillstartafternscd.service).

Device:thisclassencapsulatesaexistsin a hiveLinux devicein the devicetree.Eachdeviceusingudevrulesmarkallsystemdwillappearasanequipmentunit.

Mount:thistype of hivepackageamountpointof the filesystemhierarchy.Systemd will bemonitoredandmanagedonthismountpoint.For example,canbemountedautomaticallyatboottime;can beunloadedautomaticallyundercertainconditions.Systemd willconvert the entriesin the/etc/fstabmountpoints,andwhenpoweredon.

Automount:thistype of hivepackagingsystemsin the hierarchyofamountpoint.Eachunitcorresponds to amountingconfigurationsmountshiveswhentheautomaticmountpointisaccessed,systemdmountbehaviors that are definedin the implementation of the mountpoint.

Swap:mount the hiveand is similartoExchangeconfigurationunittomanage the swappartition.UserscanuseswappartitionExchangeconfigurationelementstodefine the system,enough tomake a swappartitionisactivatedatboottime.

Target:thistype of hive is configuredforotherlogicalgroupingunit.Themselveswithoutactuallydoinganything,justrefer to otherhives.Thisallowsaunifiedcontrolof thehive.Thiscan beachievedyouarealreadyveryfamiliar withtheconcept of runlevel.For example,want tobring the systemintographicalmode, you need to runmany of the servicesandconfigurationcommands,whicharerepresentedby the hive,combinesallthesehivesintoatarget(target),itmeansallthesehivesneed to beimplementationagaintoenter the Staterepresentedby the targetsystem is running.(For example,multi-user.targetis equivalent to the traditionalSysV systemrunlevel3)

Timer:timerhiveusedtimeduser–definedaction is triggered,thistype of hive is replacedthetiming of ATD,crondand othertraditionalservices.

Snapshot:targetsimilar to hives, a snapshotisaset of configurationelements.Itsavesthecurrentoperationalstate of the system.

Dependencies:

Systemdwillstart the worka lotoflifting to rely on,so that theycanstart.Yettherearesometasks,amongthemthere is naturallydependent,you can’tuse“socket to activate“(socketactivation),D-Bus activationandautofs, the threemethodstorelievedependence(threemethodsseesubsequentdescriptions for details).For example:mountmustwait for the mountpointiscreatedin the filesystem;alsomustwait for the correspondingphysicaldevice is mounted in place.In order tosolvethiskind of dependency,systemdhiveyou candefinedependenciesbetween.

Systemd hivekeywordin the definitionfile is usedtodescribedependenciesbetweenhives.For example:unitadependentunitb,unitb, used in the definitionof“requirea“tomean.Systemdwillensuretostartastartupb.

Systemd services:

Systemd guaranteetransactionalintegrity.Systemd conceptsand data inthedatabase is different,mainlyin order toensure thatnocircularreferencesbetweenmultipledependenthive.There are circulardependencies,thensystemdwillnotstartanyservices.Systemdwilltry toresolvetheissueat this time,because the dependenciesbetween the hivethere aretwo:requiredis a strongreliance onwantis a weakdependence onsystemdwillremovewantskeywordSpecifies that seeif youcanbreak the cycleofdependence.If youcannotrepair,systemdwillreport an error.

Systemd canautomatically detectandrepairthistype of configurationerrors,greatlyreducing the burden on administratorstroubleshoot.

Target andrunlevel:

Systemdtarget(target)replacestherunlevelconcept,providegreaterflexibility,asyoucaninheritanexistingtargetandaddotherservices,createyour owngoal.Systemdgoals are listed in the followingtableandcorrespond to the commonrunlevel:

Mostof the servicesrely on the socketison.ServicesthroughasocketportS1 to providetheirservices,otherserviceif youneedservice,youneed to connect to S1.If the service is notstarted,S1 does notexist,otherserviceswillgetbooterror.Traditionally,peopleneedtostart the service,waiting forit to enter the readystate,thenstart the otherservices that needit.Systemd believes thatas long aswe establish S1,thenalltheotherservicescanstart at the same timewithoutwaiting for the servicetocreateaS1.If the service is notstarted,thenotherprocessservicerequestswillbesenttoS1Linuxoperating systemcacheandotherprocessesinplacewaiting forthisrequest.Once the service is astartingplace,cachedrequestscan bedealt withimmediately, and everything is up and running.

Servicehow touse the socketcreatedby the initprocessit?

Linux hasafeature of the operating system,when the processcallsforkorexeccreates a childprocess,allopenedin the parentprocessfilehandles(filedescriptor)inherits the quiltprocess.Socketisafilehandle,processacancreateasocket,sincewhen a processwhenachildprocesscallsexeclaunchesanew,justmake surethesocket‘sclose_on_execflagiscleared,then the newchildprocessescaninheritthesocket.Childprocessseethesocketand the parentprocesscreatesthesocket the socketis the samesystem,itwas as ifthesocketiscreatedas the childprocess,there is nodifference.

Thisfeaturewaspreviouslyexploitedbyasystemcalled the inetdservice.Inetd processwill beresponsible formonitoring the commonsocketport,such asTelnet,connectionrequestswhentheport,inetdstarttelnetdprocessesand Sockets connected telnetdpassedto the newprocessforhandling. In this way,when the systemwhen there is noTelnetclientconnections,youdo notneed to starttelnetdprocess.Inetd canrepresent a lotofnetworkservices,so thatyoucanloadandsave a lotofsystemmemoryresourcesonlywhenthere is a realconnectionrequeststartsonlywhen the appropriateservice,and passed to the appropriate sockets ofserviceprocess.

Andlikeinetd,systemdistheparent of allotherprocesses,whichcanset upall the requiredsocket,thencallEXECwillpassthesocketto the newserviceprocess,and the newprocessdirectlyusingthesocketservices.

Start the secondprinciple:resolvingD-Bus dependence

D-Bus isshort fordesktop-bus,isalowlatency,lowoverhead,highavailabilityofinter-processcommunicationmechanism.It is increasingly being used forcommunicationbetweenapplications, and is alsoused forcommunicationbetween the applicationand the operating systemkernel.ManymodernserviceprocessesuseD-Bus instead of Socketsasinterprocesscommunicationmechanisms,providesservices.NetworkManager simplifiesLinux networkconfigurationservices,for example,useD-Bus andinteract with otherapplicationsorservices:softwareevolutionmailclientavailablethroughD-Bus from the NetworkManager servicenetworkstatechanges,so as to ensureappropriatetreatment.

D-Bus supports the so-called“busactivation“function.If the service is arequiredservicebD-Bus services,whileservicebdoesnotrun,youcanD-Bus in the servicestart the serviceautomaticallywhenarequestservicebD-Bus b.ServicearequestisissuedbyD-Bus cache,awillbwaiting forservice to start in place of service.Withthisfeature,rely ond-busservicecan bestarted in parallel.

Startprinciplethree:resolvingfilesystemdepends on

Duringsystemstartup,filesystemrelatedactivitiesis the mosttime consuming,such asmountingfilesystems,diskforfilesystemcheck(fsck),diskquotacheckingis a verytime-consumingoperation.Whilewaiting for the completion of theseworks, the systemisidle.Theserviceseems tohave to wait forthose whowant tousefilesystemfilesysteminitialization to completebefore theycanstart.Butsystemdfoundthisdependencecould beavoided.

Systemd autofsreferencedesign,make the dependentfilesystemservicesandinitializingboth the filesystemitselfcanworkconcurrently.Autofscanmonitortherealaccesstoafilesystemmountpoint,totrigger a mountoperation,whichisrealizedthrough the kernelautomountermodulesupport.For example,anopen()systemcallfunction“/Misc/CD/File1“when/Misc/CDnotperform a mountoperation,open()callissuspendedwaiting for,Linux kernelnotifies the autofs,autofs to perform the mount.At this time,control is returnedto the open()systemcallandopens the filesproperly.

Systemd autofs–integratedimplementationformountpointsin the system,such as/home,when the systemstartswhensystemdautomaticallytocreateatemporarymountpoint./Homeatthistime the realmount a devicenotstartedwell,truemountoperationisnotimplementedfilesystemdetectionhasnot yetcompleted.Butthose whorely onthecontentsofprocesscanstart,theyopen()operationisbuiltinto theautofscapturesystemd,theopen()callspending(interruptiblesleepstate).Thenwait for the realmountoperation is complete,filesystemtesting is alsocompleted,systemdreplacestheautomaticmountpoint with therealmountpoints,andopen()callreturns.Thus,realizethatdepend on filesystemservicesandfilesystemitselfat the start.

Of course,for“/“rootdependencemustactuallybeexecutedserially,becausesystemdthemselvesarestoredunder/,mount the checkmustwait for the systemrootdirectory.

But for similar/home, hanging contains points, this concurrent can improve system of started speed, especially Dang/home is remote of NFS node, or is encryption disc,, need spent more long of time only can prepared ready of situation Xia, because concurrent started, this paragraph time within, system is not completely no thing can do, but can using this paragraph spare time do more of started process of things, overall on shortened has system started time.

Developerhasdevelopedanewserviceprogram,such ashttpd,youneedtowriteaconfigurationfileso thattheservicecanbesystemdmanagement,similar to the workof the UpStart configurationfile.Servicestartupcommandlinesyntaxdefinedinthatfile,andotherservicesanddependencies, and so on.

In additionwehavelearnedbefore,systemdfeature–bloat,not onlyformanagementservices, you canalsomanagemountpoints,define a scheduledtask.Allthisworkisdonebyediting the appropriatehivefiles.I amgivenseveralhivefiles

#DefinitionRequires thatmulti-user.targetstartedBasic.targetmustbestarted;alsobasic.targetstop#, and multi-user.targetmust bestopped.Ifyouthenview the Basic.targetfile, you willfinditsysinit.target#otherspecifiedunitmust bestarted.Alsosysinit.targetwillalsocontainotherelements.Usinglayer–by–layerlinkstructure,end# the components that need to supportmultipleuser–modeserviceisinitializingstartgood.

In additionin the/etc/systemd/systemdirectory,youcansee the directory, such as*.wants,put it inthedirectoryof a hivefile is equivalentto[Unit]wantskeywordssection,whichstarts in thisunit, you alsoneed to starttheunit.For example,youcaneasily write your own foo.servicefilein the multi-user.target.wantsdirectory,soalwaysstartsbydefault.

Thehivefiledefinesamountpoint.Mount the hivefilehasa[Mount]configurationsection,configuretheWhat,Where andType threedataitems.Thisisnecessaryfor the mountcommand,exampleconfiguration is equivalentto the followingmountcommand:

mount –t debugfs /sys/kernel/debug debugfs

Systemd systemmanagement:

Systemdsystemctlisthemaincommandlinetool.

Mostadministratorsarealreadyfamiliar with the systemmanagementservicesandinitsystem,such asusingserviceandchkconfigas well astelinitcommand.Systemdcompleted the sameadministrativetask,justdifferentsyntax for commandtoolsystemctl.

Start the service

Systemctlstarthttpd.servicefigure1:

Stop the service

Systemctlstophttpd.servicefigure2:

Restartservices

Systemctlrestarthttpd.serviceas in Figure3:

Heavy dutyservice

systemctl reloadhttpd.service

Conditionalrestart

systemctl condrestarthttpd.service

Statusview

systemctl statushttpd.service

Listoflistsyou canstartorstopservices.

systemctl list-unit-files –type=service

Settingservicestartup

chkconfig httpd on

systemctl enablehttpd.service

Cancel the servicestartup;

systemctl disablehttpd.service

Check for aservicein the currentenvironmentisconfiguredtoenableordisable.

Theessence of thisis to remove/usr/lib/systemd/system/default.target,thenlinksto the targetlevelsoftargetfile/etc/systemd/system/default.targetfile;

wKioL1X0Jgqxl2MjAACQ7hWC9-g838.jpg

Systemdisnot onlyone of the originalsystem:

Systemd is alsoresponsible forotheradministrativeconfiguration of the system,such asconfiguring the network,Locale management,managementsystemkernelmodule is loaded.

Systemd ablyhasreplacedsysvinitallfeature,butitwas not to be complacent.Because the initprocessis the parentofallprocesses of the systemprocesses the particularityofsystemdiswell suited to provideoncethefunctionalityprovidedbyotherservices,such asscheduledtasks(previouslydonebycrond),sessionmanagement(formerlymanagedbyConsoleKit/PolKit).Fromjustcoatsasintroduced in this paper,Systemd istubealot,butit is stillindevelopment.Itwillgraduallybecomeamultifunctionalsystem,able tohandlesomanysystemmanagementtasks,or evenbe thought of asanoperating system.Thisis veryhelp tostandardizemanagementofLinux!