方法一:
--------------------------------------------------
1. 在/etc/init.d/下放置启动脚本,比如postgresql
root@ubuntu:/etc/init.d# cat postgresql
#!/bin/sh
set -e

### BEGIN INIT INFO
# Provides: postgresql
# Required-Start: $local_fs $remote_fs $network $time
# Required-Stop: $local_fs $remote_fs $network $time
# Should-Start: $syslog
# Should-Stop: $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: PostgreSQL RDBMS server
### END INIT INFO

# Setting environment variables for the postmaster here does not work; please
# set them in /etc/postgresql/<version>/<cluster>/environment instead.

[ -r /usr/share/postgresql-common/init.d-functions ] || exit 0

. /usr/share/postgresql-common/init.d-functions

# versions can be specified explicitly
if [ -n "$2" ]; then
versions="$2 $3 $4 $5 $6 $7 $8 $9"
else
get_versions
fi

case "$1" in
start|stop|restart|reload)
if [ "$1" = "start" ]; then
create_socket_directory
fi
if [ -z "`pg_lsclusters -h`" ]; then
log_warning_msg 'No PostgreSQL clusters exist; see "man pg_createcluster"'
exit 0
fi
for v in $versions; do
$1 $v || EXIT=$?
done
exit ${EXIT:-0}
;;
status)
LS=`pg_lsclusters -h`
# no clusters -> unknown status
[ -n "$LS" ] || exit 4
echo "$LS" | awk 'BEGIN {rc=0} {if (match($4, "down")) rc=3; printf ("%s/%s (port %s): %s\n", $1, $2, $3, $4)}; END {exit rc}'
;;
force-reload)
for v in $versions; do
reload $v
done
;;
*)
echo "Usage: $0 {start|stop|restart|reload|force-reload|status} [version ..]"
exit 1
;;
esac

exit 0

2. 添加服务
cd /etc/init.d/
update-rc.d postgresql defaults 90

3. 删除启动
update-rc.d -f postgresql remove

方法二
-------------
1. 启动脚本:/etc/systemd/system/postgresql.service
[Unit]
Description=PostgreSQL database server
After=network.target

[Service]
Type=forking
User=postgres
Group=postgres
OOMScoreAdjust=-1000
Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
Environment=PG_OOM_ADJUST_VALUE=0
Environment=PGSTARTTIMEOUT=270
Environment=PGDATA=/data/postgresql/data
ExecStart=/usr/local/pgsql/bin/pg_ctl start -D ${PGDATA} -s -w -t ${PGSTARTTIMEOUT}
ExecStop=/usr/local/pgsql/bin/pg_ctl stop -D ${PGDATA} -s -m fast
ExecReload=/usr/local/pgsql/bin/pg_ctl reload -D ${PGDATA} -s
TimeoutSec=300

[Install]
WantedBy=multi-user.target

2. 添加启动
systemctl daemon-reload
systemctl enable postgresql

Ubuntu开机启动的方式的更多相关文章

  1. Redis之Ubuntu开机启动

    1.编译源码,生成可执行文件: 2.将生成的可执行文件拷贝到 /user/local/bin目录下,若没有x权限请加上: 3.将安装包中的 redis.conf配置文件移到/etc/redis.con ...

  2. Ubuntu 16.04设置rc.local开机启动命令/脚本的方法(通过update-rc.d管理Ubuntu开机启动程序/服务)

    注意:rc.local脚本里面启动的用户默认为root权限. 一.rc.local脚本 rc.local脚本是一个Ubuntu开机后会自动执行的脚本,我们可以在该脚本内添加命令行指令.该脚本位于/et ...

  3. Ubuntu开机启动roscore服务的设置

    1.在/etc/init.d中添加启停脚本ros_daemon.bash: #!/bin/bash ### BEGIN INIT INFO # Provides: ros_daemon.bash # ...

  4. Ubuntu 开机启动是出现 grub rescue 解决办法

    最近想在Ubuntu的基础上,再在硬盘的一个分区安装Windows,其中有次不小心,在安装windows的时候,删除了一个分区,造成下次启动Ubuntu系统出现 grub rescue 下面是我的修复 ...

  5. Ubuntu开机启动svn

    一.创建脚本 $cd /etc/init.d/$sudo vim svnserve 内容如下#! /bin/shsudo svnserve -d -r /home/svn 二.脚本权限设置 sudo ...

  6. ubuntu 开机启动shell脚本

    1.创建shell启动脚本test 2.将启动脚本复制到 /etc/init.d 目录下 3.设置脚本文件权限 sudo chmod 755 /etc/init.d/test 4.设置脚本启动 sud ...

  7. ubuntu开机启动

    /rc.local  (ran as root) https://unix.stackexchange.com/questions/210939/what-user-runs-the-commands ...

  8. Ubuntu 开机启动不执行

    解决方案: 1.将/etc/rc.local的命令改成更加兼容的模式,将"#!/bin/sh"改为"#!/bin/bash" 2.将/bin/sh重新链接到/b ...

  9. Ubuntu 16.04设置rc.local开机启动命令/脚本的方法

    Ubuntu 16.04设置rc.local开机启动命令/脚本的方法       Ubuntu 16.04设置rc.local开机启动命令/脚本的方法(通过update-rc.d管理Ubuntu开机启 ...

随机推荐

  1. 分享一些JavaScript简易小技巧

    特性检测而非浏览器检测 因为某某特性某浏览器不支持,我们经常的做法是在代码中直接先做浏览器判断如: 1 if(Broswer.isFirfox){ 2     //do something 3 } 其 ...

  2. PHP 5.4语法改进与弃用特性

    PHP 5.4于本月尘埃落定,它是 PHP 自 2009 年以来的首次重大更新.该版本对语言部分进行了增强,包括支持 Traits 和移除部分争议特性. Traits 同 Java 和 .NET 一样 ...

  3. 论文笔记《Spatial Memory for Context Reasoning in Object Detection》

    好久不写论文笔记了,不是没看,而是很少看到好的或者说值得记的了,今天被xinlei这篇paper炸了出来,这篇被据老大说xinlei自称idea of the year,所以看的时候还是很认真的,然后 ...

  4. SQLMap的前世今生(Part1)

    http://www.freebuf.com/sectool/77948.html 一.前言 谈到SQL注入,第一时间就会想到神器SQLMAP,SQLMap是一款用来检测与利用的SQL注入开源工具.那 ...

  5. POJ1062:昂贵的聘礼(dfs)

    昂贵的聘礼 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 58108   Accepted: 17536 题目链接:http ...

  6. 2017南宁现场赛E The Champion

    Bob is attending a chess competition. Now the competition is in the knockout phase. There are 2^r2r  ...

  7. 【poj3420】递推式转矩阵乘法

    历史性的时刻!!! 推了一晚上!和hyc一起萌萌哒地推出来了!! 被摧残蹂躏的智商啊!!! 然而炒鸡高兴!! (请不要介意蒟蒻的内心独白..) 设a[i]为扫到第i行时的方案数. 易知,对于一行1*4 ...

  8. 【BZOJ2648】SJY摆棋子 [KD-tree]

    SJY摆棋子 Time Limit: 20 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description 这天,SJY显得无聊.在家自己 ...

  9. es修改数据

    # 官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html#bulk-routing * ...

  10. 视频图像处理基础知识5(RGB与Ycbcr相互转换公式 )【转】

    转自:http://blog.csdn.net/Times_poem/article/details/51471438 版权声明:本文为博主原创文章,未经博主允许不得转载. 需求说明:视频处理算法基本 ...