GVKun编程网logo

linux – 在创建新的systemd服务时,何时需要将RemainAfterExit选项设置为true?

95

在本文中,您将会了解到关于linux–在创建新的systemd服务时,何时需要将RemainAfterExit选项设置为true?的新资讯,并给出一些关于.System.exit(0)和System.

在本文中,您将会了解到关于linux – 在创建新的systemd服务时,何时需要将RemainAfterExit选项设置为true?的新资讯,并给出一些关于. System.exit(0)和System.exit(1) 和return 区别、c# – LINQ to Entities不识别方法’System.String StringConvert(System.Nullable`1 [System.Double])、CentOS 7下设置Docker代理(Linux下Systemd服务的环境变量配置)、CentOS 7下设置Docker代理(Linux下Systemd服务的环境变量配置)的实用技巧。

本文目录一览:

linux – 在创建新的systemd服务时,何时需要将RemainAfterExit选项设置为true?

linux – 在创建新的systemd服务时,何时需要将RemainAfterExit选项设置为true?

我正在尝试写一些服务.他们中的一些人将’type’选项设置为oneshot.但是当选项’RemainAfterExit’需要设置为true时,我仍然感到困惑. (不仅仅是该服务即使在退出后也需要活跃).

解决方法

对服务使用RemainAfterExit = yes,这会以某种方式改变系统的状态.当您希望恢复该状态时,您只需停止该服务即可.然后你可以再次启动它,但不能没有先停止它.一个例子是service,它在文件系统中创建一个标志,供其他应用程序使用.在开始时,它创建标志文件,然后存在,但systemd将服务保持为活动状态.然后你可以停止它,它将删除标志文件.

对于执行某些操作但不更改系统状态的服务,请使用RemainAfterExit = no.一个例子是清理/ tmp服务.你启动它,它将完成它的工作然后不活动(不需要停止它).你可以随时重新开始它,并将再次开始工作(清理).

. System.exit(0)和System.exit(1) 和return 区别

. System.exit(0)和System.exit(1) 和return 区别

1、System.exit(0)和System.exit(1)有什么区别?
2、在什么情况下执行System.exit()不会抛出异常?如果抛出了SecurityException异常,一般是因为什么原因?
3、如果我想中止当前运行的java程序,除了执行System.exit()还能用什么方法?

 

 

1。程序返回值不同。
2。抛出SecurityException是因为你调用了不允许的操作。比如在Applet中操作本地文件,或者在RMI程序中操作不允许的文件。Sun对于这个有专门的文章和解决方法。
3。对于java程序,运行System.exit()会终止JVM,所以Servlet和Applet中都不应该显示调用这个方法。

 

2個同為exit
public static void exit(int status)终止当前正在运行的 Java 虚拟机。参数用作状态码;根据惯例,非零的状态码表示异常终止。零状态是终止整个程序。

 

 

 

如果在main方法中System.exit(0)与return 没有区别,都是终止程序。

如果是别的方法,那System.exit(0)直接终止程序,就算后面有代码也不执行了
而return则返回至调用该方法的地方,如果后面还有代码则继续执行

 

2.解析

查看java.lang.System的源代码,我们可以找到System.exit(status)这个方法的说明,代码如下:

 

/** * Terminates the currently running Java Virtual Machine. The * argument serves as a status code; by convention, a nonzero status * code indicates abnormal termination. * <p> * This method calls the <code>exit</code> method in class * <code>Runtime</code>. This method never returns normally. * <p> * The call <code>System.exit(n)</code> is effectively equivalent to * the call: * <blockquote><pre> * Runtime.getRuntime().exit(n) * </pre></blockquote> * * @param status exit status. * @throws SecurityException * if a security manager exists and its <code>checkExit</code> * method doesn''t allow exit with the specified status. * @see java.lang.Runtime#exit(int) */ public static void exit(int status) { Runtime.getRuntime().exit(status); }注释中说的很清楚,这个方法是用来结束当前正在运行中的java虚拟机。如何status是非零参数,那么表示是非正常退出。

 

  1. System.exit(0)是将你的整个虚拟机里的内容都停掉了 ,而dispose()只是关闭这个窗口,但是并没有停止整个application exit() 。无论如何,内存都释放了!也就是说连JVM都关闭了,内存里根本不可能还有什么东西
  2. System.exit(0)是正常退出程序,而System.exit(1)或者说非0表示非正常退出程序
  3. System.exit(status)不管status为何值都会退出程序。和return 相比有以下不同点: return是回到上一层,而System.exit(status)是回到最上层

 

3.示例

在一个if-else判断中,如果我们程序是按照我们预想的执行,到最后我们需要停止程序,那么我们使用System.exit(0),而System.exit(1)一般放在catch块中,当捕获到异常,需要停止程序,我们使用System.exit(1)。这个status=1是用来表示这个程序是非正常退出。

c# – LINQ to Entities不识别方法’System.String StringConvert(System.Nullable`1 [System.Double])

c# – LINQ to Entities不识别方法’System.String StringConvert(System.Nullable`1 [System.Double])

我不知道为什么我得到这个错误.我已经使用这个功能与以前版本的实体框架,但我已经设置了一个新的项目使用EF6,它不合作.
using System.Data;
using System.Data.Objects.sqlClient;

e.Result = from n in MyDB.tblBulletins
     where n.AnncStart <= DateTime.Now && n.AnncEnd > DateTime.Now && n.Approved == true
     orderby n.AnncStart descending,n.AnncDate descending
     select new
     {
        n.RecID,AnncTitle = n.AnncTitle + " <a href='bulletinAdd.aspx?ID=" + sqlFunctions.StringConvert((double)n.RecID).Trim() + "'><Edit></a>",AnncText = (n.AnncImg == null ? n.AnncText : "<a href='images/bulletin/" + n.AnncImg + "'><img src='images/bulletin/" + n.AnncImg + "'alt='Click for larger image'/></a>" + n.AnncText),Email = (n.Email == null ? "" : "<br/><a href='mailto:" + n.Email + "'>" + n.Email + "</a>"),n.AnncType,n.AnncDate,n.AnncEnd,n.v_EmpBasicInfo.Name
      };

当我运行这个我得到
LINQ to Entities不会识别方法’System.String StringConvert(System.Nullable`1 [System.Double])’方法,并且此方法不能转换为存储表达式.

n.RecID是sql数据库中的表上的一个int主键(sql Server Standard Edition)

所有我似乎通过搜索找到的人是推荐StringConvert而不是ToString

添加 – 堆栈跟踪:

[NotSupportedException: LINQ to Entities does not recognize the method 'System.String StringConvert(System.Nullable`1[System.Double])' method,and this method cannot be translated into a store expression.]
System.Data.Entity.Core.Objects.ELinq.DefaultTranslator.Translate(ExpressionConverter parent,MethodCallExpression call) +194
System.Data.Entity.Core.Objects.ELinq.MethodCallTranslator.TypedTranslate(ExpressionConverter parent,MethodCallExpression linq) +976
System.Data.Entity.Core.Objects.ELinq.TypedTranslator`1.Translate(ExpressionConverter parent,Expression linq) +88
System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq) +148
System.Data.Entity.Core.Objects.ELinq.BinaryTranslator.TypedTranslate(ExpressionConverter parent,BinaryExpression linq) +122
System.Data.Entity.Core.Objects.ELinq.TypedTranslator`1.Translate(ExpressionConverter parent,BinaryExpression linq) +87
System.Data.Entity.Core.Objects.ELinq.TypedTranslator`1.Translate(ExpressionConverter parent,Expression linq) +88
System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq) +148
System.Data.Entity.Core.Objects.ELinq.NewTranslator.TypedTranslate(ExpressionConverter parent,NewExpression linq) +520
System.Data.Entity.Core.Objects.ELinq.TypedTranslator`1.Translate(ExpressionConverter parent,Expression linq) +88
System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq) +148
System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda,DbExpression input) +168
System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda,DbExpression input,DbExpressionBinding& binding) +160
System.Data.Entity.Core.Objects.ELinq.OneLambdaTranslator.Translate(ExpressionConverter parent,MethodCallExpression call,DbExpression& source,DbExpressionBinding& sourceBinding,DbExpression& lambda) +168
System.Data.Entity.Core.Objects.ELinq.SelectTranslator.Translate(ExpressionConverter parent,MethodCallExpression call) +70
System.Data.Entity.Core.Objects.ELinq.SequenceMethodTranslator.Translate(ExpressionConverter parent,SequenceMethod sequenceMethod) +47
System.Data.Entity.Core.Objects.ELinq.MethodCallTranslator.TypedTranslate(ExpressionConverter parent,MethodCallExpression linq) +141
System.Data.Entity.Core.Objects.ELinq.TypedTranslator`1.Translate(ExpressionConverter parent,Expression linq) +88
System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq) +148
System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.Convert() +50
System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption) +563
System.Data.Entity.Core.Objects.<>c__displayClassb.<GetResults>b__a() +83
System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func`1 func,IDbExecutionStrategy executionStrategy,Boolean startLocalTransaction,Boolean releaseConnectionOnSuccess) +499
System.Data.Entity.Core.Objects.<>c__displayClassb.<GetResults>b__9() +271
System.Data.Entity.sqlServer.DefaultsqlExecutionStrategy.Execute(Func`1 operation) +251
System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) +600
   System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0() +89
System.Lazy`1.CreateValue() +416
System.Lazy`1.LazyInitValue() +152
System.Lazy`1.get_Value() +75
System.Data.Entity.Internal.LazyEnumerator`1.MoveNext() +40
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +381
System.Linq.Enumerable.ToList(IEnumerable`1 source) +58

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeMethodHandle.InvokeMethod(Object target,Object[] arguments,Signature sig,Boolean constructor) +0
System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,Object[] parameters,Object[] arguments) +92
System.Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags invokeAttr,Binder binder,CultureInfo culture) +108
System.Reflection.MethodBase.Invoke(Object obj,Object[] parameters) +19
System.Web.UI.WebControls.QueryableDataSourceHelper.ToList(IQueryable query,Type dataObjectType) +225
System.Web.UI.WebControls.LinqDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +549
System.Web.UI.WebControls.Repeater.GetData() +55
System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +89
System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +61
System.Web.UI.WebControls.Repeater.DataBind() +105
System.Web.UI.WebControls.Repeater.EnsureDataBound() +49
System.Web.UI.WebControls.Repeater.OnPreRender(EventArgs e) +15
System.Web.UI.Control.PreRenderRecursiveInternal() +83
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterasyncPoint) +974

解决方法

我有同样的问题,意识到我正在使用错误的sqlFunction类型.请确保您引用了正确的命名空间:
using System.Data.Entity.sqlServer;

并不是:

using System.Data.Objects.sqlClient;

CentOS 7下设置Docker代理(Linux下Systemd服务的环境变量配置)

CentOS 7下设置Docker代理(Linux下Systemd服务的环境变量配置)

Docker守护程序使用HTTP_PROXYHTTPS_PROXY以及NO_PROXY环境变量在其启动环境来配置HTTP或HTTPS代理的行为。无法使用daemon.json文件配置这些环境变量。

此示例将覆盖默认docker.service文件。

在设置中,需要在Docker systemd服务文件中添加此配置

如果使用HTTP代理服务器时,将为docker服务创建systemd插件目录:

mkdir -p /etc/systemd/system/docker.service.d

创建一个名为的文件/etc/systemd/system/docker.service.d/http-proxy.conf,添加HTTP_PROXY环境变量:

[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/"

或者,如果使用HTTPS代理服务器,那么再创建一个名为/etc/systemd/system/docker.service.d/https-proxy.conf添加HTTPS_PROXY环境变量:

[Service]
Environment="HTTPS_PROXY=https://proxy.example.com:443/"

为Docker配置不代理的地址时,可以通过NO_PROXY环境变量指定它们,比如HTTP代理服务器的配置:

[Service]    
Environment="HTTP_PROXY=http://proxy.example.com:80/" "NO_PROXY=localhost,127.0.0.1,docker-registry.somecorporation.com"

或者,HTTPS代理服务器的配置:

[Service]    
Environment="HTTPS_PROXY=https://proxy.example.com:443/" "NO_PROXY=localhost,127.0.0.1,docker-registry.somecorporation.com"

重新读取服务的配置文件:

systemctl daemon-reload

重启Docker:

systemctl restart docker

验证是否已加载配置:

systemctl show --property=Environment docker

参考:

https://docs.docker.com/config/daemon/systemd/

以上就是CentOS 7下设置Docker代理(Linux下Systemd服务的环境变量配置)的详细内容,更多关于docker配置systemd服务的资料请关注其它相关文章!

您可能感兴趣的文章:
  • linux 系统进程管理工具systemd详解(systemctl命令、创建自己的systemd服务)
  • 使用systemd部署服务的过程解析
  • Nginx服务器添加Systemd自定义服务过程解析
  • CentOS7 systemd添加自定义系统服务的方法
  • Centos7启动流程及Systemd中Nginx启动配置
  • 深入浅析centos7中的systemd
  • Systemd 入门实战教程

CentOS 7下设置Docker代理(Linux下Systemd服务的环境变量配置)

CentOS 7下设置Docker代理(Linux下Systemd服务的环境变量配置)

Docker守护程序使用HTTP_PROXYHTTPS_PROXY以及NO_PROXY环境变量在其启动环境来配置HTTP或HTTPS代理的行为。无法使用daemon.json文件配置这些环境变量

此示例将覆盖默认docker.service文件。

在设置中,需要在Docker systemd服务文件中添加此配置

如果使用HTTP代理服务器时,将为docker服务创建systemd插件目录:

mkdir -p /etc/systemd/system/docker.service.d

创建一个名为的文件/etc/systemd/system/docker.service.d/http-proxy.conf,添加HTTP_PROXY环境变量:

[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/"

或者,如果使用HTTPS代理服务器,那么再创建一个名为/etc/systemd/system/docker.service.d/https-proxy.conf 添加HTTPS_PROXY环境变量 

[Service]
Environment="HTTPS_PROXY=https://proxy.example.com:443/"

 

为Docker配置不代理的地址时,可以通过NO_PROXY环境变量指定它们,比如HTTP代理服务器的配置

[Service]    
Environment="HTTP_PROXY=http://proxy.example.com:80/" "NO_PROXY=localhost,127.0.0.1,docker-registry.somecorporation.com"

或者,HTTPS代理服务器的配置:

[Service]    
Environment="HTTPS_PROXY=https://proxy.example.com:443/" "NO_PROXY=localhost,127.0.0.1,docker-registry.somecorporation.com"

 

重新读取服务的配置文件:

systemctl daemon-reload

 

重启Docker:

systemctl restart docker

 

验证是否已加载配置:

systemctl show --property=Environment docker

 

参考:

https://docs.docker.com/config/daemon/systemd/#httphttps-proxy

关于linux – 在创建新的systemd服务时,何时需要将RemainAfterExit选项设置为true?的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于. System.exit(0)和System.exit(1) 和return 区别、c# – LINQ to Entities不识别方法’System.String StringConvert(System.Nullable`1 [System.Double])、CentOS 7下设置Docker代理(Linux下Systemd服务的环境变量配置)、CentOS 7下设置Docker代理(Linux下Systemd服务的环境变量配置)等相关知识的信息别忘了在本站进行查找喔。

本文标签: