| 
									
										
										
										
											2013-11-05 18:10:22 +04:00
										 |  |  | #!/usr/bin/env watchman | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | unset reload | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-26 01:57:59 +04:00
										 |  |  | service_command='/usr/bin/cjdroute' | 
					
						
							| 
									
										
										
										
											2014-04-04 15:40:00 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-05 11:52:51 +04:00
										 |  |  | cjdroute_config='/etc/cjdroute.conf' | 
					
						
							| 
									
										
										
										
											2014-04-05 23:59:52 +04:00
										 |  |  | cjdroute_admin_port='11234' | 
					
						
							| 
									
										
										
										
											2013-11-05 18:10:22 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-13 11:04:27 +04:00
										 |  |  | cjdroute.check_tun_module() { | 
					
						
							|  |  |  | 	[[ -e '/dev/net/tun' ]] || { | 
					
						
							|  |  |  | 		modprobe tun || { | 
					
						
							|  |  |  | 			watchman.err "Could not load module tun!" | 
					
						
							|  |  |  | 			return 1 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-05 11:52:51 +04:00
										 |  |  | get_pid() { | 
					
						
							| 
									
										
										
										
											2014-04-05 23:59:52 +04:00
										 |  |  | 	lsof -i :"$cjdroute_admin_port" | tail -1 | cut -d ' ' -f 2 | 
					
						
							| 
									
										
										
										
											2014-04-05 11:52:51 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-05 18:10:22 +04:00
										 |  |  | start() { | 
					
						
							| 
									
										
										
										
											2013-11-13 11:04:27 +04:00
										 |  |  | 	cjdroute.check_tun_module || { return 1; } | 
					
						
							| 
									
										
										
										
											2014-02-26 01:57:59 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	[[ -e "$cjdroute_config" ]] || { | 
					
						
							|  |  |  | 		watchman.err "$cjdroute_config does not exist, please create it by running cjdroute --genconf >> /etc/cjdroute.conf" | 
					
						
							|  |  |  | 		return 1 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-28 10:54:06 +04:00
										 |  |  | 	"$service_command" < "${cjdroute_config}" &>"$service_logfile" && { | 
					
						
							|  |  |  | 		watchman.msg "${service_name} started" | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-11-05 18:10:22 +04:00
										 |  |  | } |