I am pondering this problem here, the course Mat-2.3148 Dynamic Optimization in Aalto University, i.e.
Find the function $x(t)$ such that $\int_0^{\infty}e^{-rt}(x^2+2x+\dot x^2)\ \mathrm dt$ has the largest value when $x(0)=1$.
I believed that the Euler is $g_x-\frac{\mathrm d}{\mathrm dt}g_{\dot x} =0$ but I cannot get the solution $1+x+rx'-x''=0$. I believe we use non-extended $\mathbb R$ (not containing $\infty$ as point) so I believe I have here a closed $t_i$ and open $t_f$?
What is the Euler equation with the closed boundary $t_i=0$ and $t_f$ to $\infty$?
I think you are over complicating it. The solution you provided assumes $t_f<\infty$, but then takes a limit, so the Euler-Lagrange equation does not change. To work out the Euler-Lagrange differential equation:
Start with the argument of the integral $$ L=e^{-rt}\left(x^2+2x+\dot{x}^2\right) $$
Then the time derivative of the partial of the Lagrangian, $L$, with respect to $\dot{x}$ is $$ \frac{\partial L}{\partial \dot{x}}=2e^{-rt}\dot{x} $$ and $$ \frac{d}{dt}\left\{\frac{\partial L}{\partial \dot{x}}\right\}=-2re^{-rt}\dot{x}+2e^{-rt}\ddot{x}. $$
Looking at the derivative of the Lagrangian with respect to $x$ we get $$ \frac{\partial L}{\partial x}=2e^{-rt}x+2e^{-rt}. $$
Finally, \begin{eqnarray*} \frac{d}{dt}\left\{\frac{\partial L}{\partial \dot{x}}\right\}-\frac{\partial L}{\partial x}=&-2re^{-rt}\dot{x}+2e^{-rt}\ddot{x}-(2e^{-rt}x+2e^{-rt})&=0\\ =&\ddot{x}-r\dot{x}-x-1&=0. \end{eqnarray*}
From here we solve this to get $$ x(t)=-1+C_1e^{\lambda_+t}+C_2e^{\lambda_-t} $$ where $$ \lambda_\pm=\frac{r\pm\sqrt{r^2+4}}{2}. $$ Now, plug x(0)=1 into the equation and you get the expression that $C_2=2-C_1$. Finally, notice that in order for the integral to be finite you must cancel out the term with the positive eigenvalue ($\lambda_+$) so $C_1=2$, i.e. the solution.